@@ -21,26 +21,25 @@ inline double to_degrees(double radians)
2121// for finding circles for thermals
2222// https://github.com/marcin-osowski/igc_lib/blob/master/igc_lib.py
2323static inline
24- void calculate_bearing_change (gsm_inmemory_db &db, int &nodesIterator )
24+ void calculate_bearing_change (gsm_inmemory_db &db, int &bFixIterator )
2525{
2626 double previousLong = ' \0 ' ;
2727 double previousLat = ' \0 ' ;
2828 long long previousTime = ' \0 ' ;
2929 double previousBearing = ' \0 ' ;
30-
31- for (auto &bFix : db.O [nodesIterator].phi [" b_fix" ])
30+ for (auto &bFix : db.O [bFixIterator].phi [" b_fix" ])
3231 {
3332 double nowLong;
3433 double nowLat;
3534 long long nowTime;
36- for (auto &data : db.O [bFix.id ].phi [ " data " ] )
35+ for (int i = 0 ; i < db.O [bFix.id ].ell . size (); i++ )
3736 {
38- if (db.O [data .id ].ell [0 ] == " latitude_double" )
39- nowLat = stod (db.O [data .id ].xi [0 ]);
40- else if (db.O [data .id ].ell [0 ] == " longitude_double" )
41- nowLong = stod (db.O [data .id ].xi [0 ]);
42- else if (db.O [data .id ].ell [0 ] == " unix_time" )
43- nowTime = stoll (db.O [data .id ].xi [0 ]);
37+ if (db.O [bFix .id ].ell [i ] == " latitude_double" )
38+ nowLat = stod (db.O [bFix .id ].xi [i ]);
39+ else if (db.O [bFix .id ].ell [i ] == " longitude_double" )
40+ nowLong = stod (db.O [bFix .id ].xi [i ]);
41+ else if (db.O [bFix .id ].ell [i ] == " unix_time" )
42+ nowTime = stoll (db.O [bFix .id ].xi [i ]);
4443 else
4544 continue ;
4645 }
@@ -49,6 +48,8 @@ void calculate_bearing_change(gsm_inmemory_db &db, int &nodesIterator)
4948 previousLat = nowLat;
5049 previousLong = nowLong;
5150 previousTime = nowTime;
51+ db.O [bFix.id ].ell .push_back (" bearing_rate" );
52+ db.O [bFix.id ].xi .push_back (std::to_string (0 ));
5253 continue ;
5354 }
5455
@@ -70,6 +71,8 @@ void calculate_bearing_change(gsm_inmemory_db &db, int &nodesIterator)
7071 if (previousBearing == ' \0 ' )
7172 {
7273 previousBearing = bearing;
74+ db.O [bFix.id ].ell .push_back (" bearing_rate" );
75+ db.O [bFix.id ].xi .push_back (std::to_string (0 ));
7376 }
7477 else
7578 {
@@ -82,16 +85,15 @@ void calculate_bearing_change(gsm_inmemory_db &db, int &nodesIterator)
8285 bearingChange -= 360.0 ;
8386 }
8487 double changeRate = bearingChange/timeDiff;
85- std::cout << " chng:" << changeRate << std::endl;
88+ db.O [bFix.id ].ell .push_back (" bearing_rate" );
89+ db.O [bFix.id ].xi .push_back (std::to_string (changeRate));
8690 }
8791
8892 }
8993}
9094
91-
92-
9395static inline
94- void calculate_lift (gsm_inmemory_db &db, int &bFixesIterator, int &iterator)
96+ int calculate_lift (gsm_inmemory_db &db, int &bFixesIterator, int &iterator)
9597{
9698 std::vector<gsm_object_xi_content> tablePhiLifts = {};
9799 std::vector<double > scoresLifts = {};
@@ -100,7 +102,8 @@ void calculate_lift(gsm_inmemory_db &db, int &bFixesIterator, int &iterator)
100102 int previousId;
101103 int previousAltitude = ' \0 ' ;
102104 bool newLiftSeries = true ;
103-
105+ // TODO:delete
106+ int counter = 0 ;
104107 for (auto &bFix : db.O [bFixesIterator].phi [" b_fix" ])
105108 {
106109 int altitude;
@@ -134,11 +137,11 @@ void calculate_lift(gsm_inmemory_db &db, int &bFixesIterator, int &iterator)
134137 scoresLift.emplace_back (1.0 );
135138 tablePhiLift.emplace_back (bFix.id );
136139 scoresLift.emplace_back (1.0 );
137-
140+ counter++;
138141 create_fast (db, ++iterator, {" lift" }, {std::to_string (diffAltitude)}, {scoresLift},
139- {{" altitudes " , {tablePhiLift}}});
140- tablePhiLiftSeries.push_back (iterator);
141- scoresLiftSeries.push_back (1.0 );
142+ {{" b_fix " , {tablePhiLift}}});
143+ tablePhiLiftSeries.emplace_back (iterator);
144+ scoresLiftSeries.emplace_back (1.0 );
142145 }
143146 else
144147 {
@@ -154,6 +157,8 @@ void calculate_lift(gsm_inmemory_db &db, int &bFixesIterator, int &iterator)
154157 previousId = bFix.id ;
155158 }
156159 create_fast (db, ++iterator, {" lifts" }, {}, {scoresLifts}, {{" lift_series" , {tablePhiLifts}}});
160+ std::cout << " count of lifts added:" << counter << ' \n ' ;
161+ return iterator;
157162}
158163
159164// https://github.com/chrisveness/latlon-geohash/blob/master/latlon-geohash.js
@@ -264,10 +269,8 @@ int vcweather_load(gsm_inmemory_db &db, int &iterator, double lat, double lon, s
264269 std::string vcPath = " /home/neo/gsm_gsql/json_files/vc" + fileName;
265270 if (std::filesystem::exists (vcPath))
266271 {
267-
268272 std::string path = " /home/neo/gsm_gsql/json_files/vc" + fileName;
269- load_jsonEllXiFile (db, path, iterator, {" currentConditions" }, " weather_vc" );
270- result = iterator;
273+ result = load_jsonEllXiFile (db, path, iterator, {" currentConditions" }, " weather_vc" );
271274 }
272275 else
273276 {
@@ -282,14 +285,12 @@ int vcweather_load(gsm_inmemory_db &db, int &iterator, double lat, double lon, s
282285 << " ?key=" << visualCrossingApiKey
283286 << " &include=current" ;
284287
285-
286288 std::string url = vc.str ();
287289 std::string weatherString = weather_curl (url);
288290
289291 std::ofstream vcFile (" /home/neo/gsm_gsql/json_files/vc" + fileName);
290292 vcFile << weatherString;
291- result = iterator;
292- load_jsonEllXiData (db, weatherString, iterator, {" currentConditions" }, " weather_vc" );
293+ result = load_jsonEllXiData (db, weatherString, iterator, {" currentConditions" }, " weather_vc" );
293294 }
294295 return result;
295296}
@@ -366,7 +367,7 @@ int generate_weatherbucket(gsm_inmemory_db& db, int bFixesIterator, int& iterato
366367 create_fast (db, ++iterator, {" geohashes" });
367368 int ghIterator = iterator;
368369 long long unixTime;
369- for (auto &bFix: db.O [bFixesIterator].phi [" b_fix" ])
370+ for (auto &bFix: db.O [bFixesIterator].phi [" b_fix" ])
370371 {
371372 double lat;
372373 double lon;
@@ -391,28 +392,21 @@ int generate_weatherbucket(gsm_inmemory_db& db, int bFixesIterator, int& iterato
391392 db.O [ghIterator].phi [geoHashCombo].emplace_back (iterator);
392393 db.O [ghIterator].scores .emplace_back (1.0 );
393394
394- /* std::vector<int> weatherBucket = weather_load(db, iterator, lat, lon, unixTime);
395- for(auto &wb : weatherBucket)
396- {
397- db.O[ghIterator].phi[geoHashCombo].emplace_back(wb);
398- db.O[ghIterator].scores.emplace_back(1.0);
399- }*/
400- db.O [iterator].phi [" bFix" ].emplace_back (bFix.id );
395+ db.O [iterator].phi [" b_fix" ].emplace_back (bFix.id );
401396 db.O [iterator].scores .emplace_back (1.0 );
402397
403398 int weatherBucket = vcweather_load (db, iterator, lat, lon, unixTime);
404- int id = db.O [ghIterator].phi [geoHashCombo]. at ( 0 ) .id ;
399+ int id = db.O [ghIterator].phi [geoHashCombo][ 0 ] .id ;
405400
406401 db.O [id].phi [" weather" ].emplace_back (weatherBucket);
407402 db.O [id].scores .emplace_back (1.0 );
408403 }
409404 else
410405 {
411- int id = db.O [ghIterator].phi [geoHashCombo]. at ( 0 ) .id ;
412- db.O [id].phi [" bFix " ].emplace_back (bFix.id );
406+ int id = db.O [ghIterator].phi [geoHashCombo][ 0 ] .id ;
407+ db.O [id].phi [" b_fix " ].emplace_back (bFix.id );
413408 db.O [id].scores .emplace_back (1.0 );
414409 }
415-
416410 }
417411 return ghIterator;
418412}
@@ -434,11 +428,18 @@ int generate_weatherbucket(gsm_inmemory_db& db, int bFixesIterator, int& iterato
434428
435429// VC
436430
437- void export_csv (gsm_inmemory_db & db, int &iterator, int geoHashesIterator)
431+ void export_csv (gsm_inmemory_db& db, int &iterator, int geoHashesIterator, int liftsIterator, gsm_db_indices& idx, std::string csvFileName )
438432{
439433 std::string headers;
440434 bool getHeaders = true ;
441- std::ofstream fileOut (" /home/neo/gsm_gsql/csv_files/test.csv" );
435+ std::string fn = " /home/neo/gsm_gsql/csv_files/" + csvFileName;
436+ std::ofstream fileOut (fn);
437+ // TODO:delete
438+ int counter = 0 ;
439+ int sumOfBfix = 0 ;
440+ int sumOfLiftSizes = 0 ;
441+ std::vector<std::string> ignoreIgc = {}; // "latitude_double", "longitude_double", "unix_time"
442+
442443 for (auto & [geoHashString, geoHashVector] : db.O [geoHashesIterator].phi )
443444 {
444445 std::string weatherLine = " " ;
@@ -454,6 +455,7 @@ void export_csv(gsm_inmemory_db &db, int &iterator, int geoHashesIterator)
454455 }
455456 weatherLine += std::to_string (weather);
456457 weatherLine += ' ,' ;
458+
457459 for (int i = 1 ; i < db.O [weather].ell .size (); i++)
458460 {
459461 weatherLine += db.O [weather].xi [i];
@@ -465,18 +467,45 @@ void export_csv(gsm_inmemory_db &db, int &iterator, int geoHashesIterator)
465467 }
466468 }
467469
468- for (auto & bFix : db.O [geoHash.id ].phi [" bFix " ])
470+ for (auto & bFix : db.O [geoHash.id ].phi [" b_fix " ])
469471 {
470- std::string csvLine = weatherLine;
471- if (getHeaders)
472+ bool isInLift = false ;
473+ sumOfBfix++;
474+ /*
475+ for(auto& lift_series : db.O[liftsIterator].phi["lift_series"])
472476 {
473- headers += db.O [bFix.id ].ell [0 ];
474- headers += ' ,' ;
477+ //TODO:delete
478+ size_t dst = idx.containedBy.addUniqueStateOrGetExisting(db.O[lift_series.id].phi["lift"][0].id);
479+ for(auto const& it : idx.containedBy.outgoingEdgesById2(idx.containedBy.addUniqueStateOrGetExisting(bFix.id)))
480+ {
481+ if(it.second == dst)
482+ {
483+ //TODO:delete
484+ counter++;
485+ isInLift = true;
486+ }
487+ }
488+ if(isInLift)
489+ break;
490+ }*/
491+ size_t liftSeriesId = db.O [liftsIterator].phi [" lift_series" ][0 ].id ;
492+ size_t dst = idx.containedBy .addUniqueStateOrGetExisting (db.O [liftSeriesId].phi [" lift" ][0 ].id );
493+ for (auto const & it : idx.containedBy .outgoingEdgesById2 (idx.containedBy .addUniqueStateOrGetExisting (bFix.id )))
494+ {
495+ if (it.second == dst)
496+ {
497+ // TODO:delete
498+ counter++;
499+ isInLift = true ;
500+ break ;
501+ }
475502 }
476- csvLine += std::to_string (bFix. id );
477- csvLine += ' , ' ;
503+
504+ std::string csvLine = weatherLine ;
478505 for (int i = 1 ; i < db.O [bFix.id ].ell .size (); i++)
479506 {
507+ if (std::find (ignoreIgc.begin (), ignoreIgc.end (), db.O [bFix.id ].ell [i]) != ignoreIgc.end ())
508+ continue ;
480509 csvLine += db.O [bFix.id ].xi [i];
481510 csvLine += ' ,' ;
482511 if (getHeaders)
@@ -485,17 +514,36 @@ void export_csv(gsm_inmemory_db &db, int &iterator, int geoHashesIterator)
485514 headers += ' ,' ;
486515 }
487516 }
517+
518+ headers += " lift" ;
519+ csvLine += (isInLift ? ' 1' : ' 0' );
520+
488521 if (getHeaders)
489522 {
490- headers.pop_back (); // remove last comma ,
491523 fileOut << headers << ' \n ' ;
492524 getHeaders = false ;
493525 }
494- csvLine.pop_back (); // remove last comma ,
495526 fileOut << csvLine << ' \n ' ;
496527 }
497528 }
498529 }
499-
530+ // TODO:delete
531+ std::cout << " counter_export_csv:" << counter << ' \n ' ;
532+ std::cout << " sum of bfix in geohash:" << sumOfBfix << ' \n ' ;
533+ int liftInLiftSeries = 0 ;
534+ std::set<size_t > bfigzIdset;
535+ for (auto &lifto_series : db.O [liftsIterator].phi [" lift_series" ])
536+ {
537+ for (auto & lifto : db.O [lifto_series.id ].phi [" lift" ])
538+ {
539+ liftInLiftSeries++;
540+ for (auto & bfigz : db.O [lifto.id ].phi [" b_fix" ])
541+ {
542+ bfigzIdset.insert (bfigz.id );
543+ }
544+ }
545+ }
546+ std::cout << " lift in lift series count:" << liftInLiftSeries << ' \n ' ;
547+ std::cout << " unique bfix.id in each lift object:" << bfigzIdset.size () << ' \n ' ;
500548}
501549#endif // GSM_GSQL_IGC_OPERATORS_H
0 commit comments