Commit d8afa1f8 by kigrig

To solo chart added avg value

parent ae70bee4
Showing with 33 additions and 7 deletions
......@@ -237,8 +237,30 @@ string createChartsOfOneYear(string name, int &pos, string aastadeVahemik){
for(int totalCounter = 0; totalCounter < riversPlaceCount; totalCounter++){
HTMLcode.append(addChart(riversPlaceNames[totalCounter], valgla[totalCounter], pos));
//SQL paring
string command = "SELECT DISTINCT seire_jogi_hydrol.hkuu, round(AVG(seire_jogi_hydrol.vaartus))\
//SQL paringud
string command = "SELECT DISTINCT seire_jogi_hydrol.haasta, AVG(seire_jogi_hydrol.vaartus)\
FROM seire_jogi_hydrol\
INNER JOIN seire_jogi_hydrol_jaamad USING (id_jaam)\
INNER JOIN joe_andmed\
ON joe_andmed.id_jogi/10 = seire_jogi_hydrol_jaamad.id_jogi\
AND joe_andmed.id_peajogi = joe_andmed.id_jogi\
AND seire_jogi_hydrol_jaamad.lavendi_nimi = '{lavendi_nimi}'\
GROUP BY seire_jogi_hydrol.haasta\
ORDER BY seire_jogi_hydrol.haasta;";
replaceInString(command, "{lavendi_nimi}", riversPlaceNames[totalCounter]);
res = PQexec(conn, command.c_str());
double keskmine;
for(int i = 0; i < PQntuples(res); i++){
keskmine += stod(PQgetvalue(res, i, 1), nullptr);
}
keskmine /= PQntuples(res);
command = "SELECT DISTINCT seire_jogi_hydrol.hkuu, round(AVG(seire_jogi_hydrol.vaartus))\
FROM seire_jogi_hydrol\
INNER JOIN seire_jogi_hydrol_jaamad USING (id_jaam)\
INNER JOIN joe_andmed\
......@@ -307,16 +329,20 @@ string createChartsOfOneYear(string name, int &pos, string aastadeVahemik){
if(rec_count > 0){
toWrite += "]},\n\t\n\t\t{ name: 'Maksimum-5%', data: [";
toWrite += " {max-5%}";
toWrite += "]},\n\t\n\t\t{ name: 'Keskmine', data: [";
for(int i = 0; i < rec_count; i++){
toWrite += ", {kesk}";
replaceInString(toWrite, "{kesk}", to_string(keskmine));
}
toWrite += "]},\n\t\n\t\t{ name: 'Maksimum-5%', data: [ {max-5%}";
replaceInString(toWrite, "{max-5%}", to_string(0.001+(long)maxValue*0.95));
for(int i = 1; i < rec_count; i++){
toWrite += ", {max-5%}";
replaceInString(toWrite, "{max-5%}", to_string((long)maxValue*0.95));
}
toWrite += "]},\n\t\n\t\t{ name: 'Maksimum+5%', data: [";
toWrite += " {max+5%}";
toWrite += "]},\n\t\n\t\t{ name: 'Maksimum+5%', data: [ {max+5%}";
replaceInString(toWrite, "{max+5%}", to_string(0.001+(long)maxValue*1.05));
for(int i = 1; i < rec_count; i++){
toWrite += ", {max+5%}";
......@@ -345,7 +371,7 @@ string createChartsOfOneYear(string name, int &pos, string aastadeVahemik){
toWrite += "\t\t\tsummary: 'Voolu hulgad, mis olid DB\\'s, teie valitud aasta eest.',\n";
toWrite += "\t\tvisuallyHiddenStyles: 'position: relative; text-align: center; top: 100%; width: 80%; left: 10%; font-size: 24px; overflow-x: auto;'\n\t\t}),\n";
toWrite += "\nChartist.plugins.ctThreshold({ threshold:";
if(rec_count > 0) toWrite += to_string(sum);
if(rec_count > 0) toWrite += to_string(keskmine);
else toWrite += to_string(0);
toWrite += "}),";
toWrite += "\t\tChartist.plugins.ctAxisTitle({\n\
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment