chiark / gitweb /
WIP per-island-pair trades
[ypp-sc-tools.db-test.git] / yarrg / rsvalue.c
1 /**/
2
3 #include "rscommon.h"
4
5 static void ipair_gettrades(int si, int di) {
6   char *stmt= masprintf
7     ("SELECT\n"
8      " sell.price               src_price,\n"
9      " sum(sell.qty)            src_qty,\n"
10      " buy.price                dst_price,\n"
11      " sum(buy.qty)             dst_qty,\n"
12      " commods.commodid         commodid,\n"
13      " commods.unitmass         unitmass,\n"
14      " commods.unitvolume       unitvolume\n"
15      " FROM commods\n"
16      " JOIN sell ON commods.commodid = sell.commodid\n"
17      " JOIN buy  ON commods.commodid = buy.commodid\n"
18      " WHERE buy.price > sell.price\n"
19      "  AND sell.islandid=%d\n"
20      "  AND buy.islandid=%d\n"
21      " GROUP BY commods.commodid, sell.price, buy.price\n",
22      si, di);
23   
24   printf("SQL\n[\n%s\n]\n", stmt);
25
26   free(stmt);
27 }
28
29 void value_route(int nislands, const int *islands) {
30   int s,d;
31   
32   for (s=0; s<nislands; s++) {
33     for (d=s; d<nislands; d++) {
34       ipair_gettrades(islands[s], islands[d]);
35     }
36   }
37
38   //char *tail;
39   //struct sqlite_vm *sth;
40   //r= sqlite_compile(db, stmt, &tail, &sth, 
41 }