Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
73
Task/CSV-data-manipulation/Aime/csv-data-manipulation.aime
Normal file
73
Task/CSV-data-manipulation/Aime/csv-data-manipulation.aime
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
void
|
||||
read_csv(list t, text path)
|
||||
{
|
||||
file f;
|
||||
list l;
|
||||
|
||||
f_affix(f, path);
|
||||
while (f_news(f, l, 0, 0, ",") ^ -1) {
|
||||
l_append(t, l);
|
||||
}
|
||||
}
|
||||
|
||||
list
|
||||
sum_columns(list t)
|
||||
{
|
||||
list c, l;
|
||||
integer i;
|
||||
|
||||
l_append(c, "SUM");
|
||||
for (i, l in t) {
|
||||
if (i) {
|
||||
integer j, sum;
|
||||
text s;
|
||||
|
||||
sum = 0;
|
||||
for (j, s in l) {
|
||||
sum += atoi(s);
|
||||
}
|
||||
|
||||
l_append(c, sum);
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
void
|
||||
add_column(list t, list c)
|
||||
{
|
||||
integer i;
|
||||
list l;
|
||||
|
||||
for (i, l in t) {
|
||||
l_append(l, c[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
write_csv(list t, text path)
|
||||
{
|
||||
integer i;
|
||||
file f;
|
||||
list l;
|
||||
|
||||
f_create(f, path, 00644);
|
||||
for (i, l in t) {
|
||||
f_(f, l[0]);
|
||||
l_ocall(l, f_, 2, 1, -1, f, ",");
|
||||
f_newline(f);
|
||||
}
|
||||
}
|
||||
|
||||
integer
|
||||
main(void)
|
||||
{
|
||||
list t;
|
||||
|
||||
read_csv(t, "tmp/CSV_data_manipulation.csv");
|
||||
add_column(t, sum_columns(t));
|
||||
write_csv(t, "tmp/CSV_data_manipulated.csv");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue