DISPLACE  1.0
A spatial model of fisheries to help sustainable fishing and maritime spatial planning
sqliteoutputstorage.h
Go to the documentation of this file.
1 #ifndef SQLITEOUTPUTSTORAGE_H
2 #define SQLITEOUTPUTSTORAGE_H
3 
4 #include "commons_global.h"
5 #include "dbtypes.h"
6 
7 #include "plottypes.h"
8 
9 #include <memory>
10 #include <string>
11 #include <vector>
12 
13 class VesselDefTable;
15 class VesselVmsLikeTable;
17 class NodesDefTable;
18 class NodesEnvtTable;
19 class NodesStatTable;
21 class PopTable;
22 class Fishfarm;
23 class Windmill;
24 class WindfarmsTable;
25 class Vessel;
26 class Ship;
27 class Population;
28 class Node;
29 class MetadataTable;
30 class FuncGroupsTable;
31 class FishFarmsDefTable;
32 
33 namespace sqlite {
34 class SQLiteStorage;
35 }
36 
38 {
39  struct Impl;
40  std::unique_ptr<Impl> p;
41 
42  static const int CURRENT_DB_SCHEMA_VERSION;
43 public:
44  explicit SQLiteOutputStorage(std::string path);
45  ~SQLiteOutputStorage() noexcept;
46 
47  void open();
48  void close();
49 
51  int versionNumber();
52 
54  int currentSchemaNumber();
55 
56  bool isOutdated() { return versionNumber() < currentSchemaNumber(); }
57 
58  void startDayLoop();
59  void endDayLoop();
60 
61  void createAllTables();
62  void createAllIndexes();
63 
64  std::shared_ptr<VesselDefTable> getVesselDefTable() const;
65  std::shared_ptr<VesselsLoglikeTable> getVesselLoglikeTable() const;
66  std::shared_ptr<VesselVmsLikeTable> getVesselVmsLikeTable() const;
67  std::shared_ptr<VesselVmsLikeFPingsOnlyTable> getVesselVmsLikeFPingsOnlyTable() const;
68  std::shared_ptr<NodesDefTable> getNodesDefTable() const;
69  std::shared_ptr<NodesEnvtTable> getNodesEnvtTable() const;
70  std::shared_ptr<NodesStatTable> getNodesStatTable() const;
71  std::shared_ptr<NodesTariffStatTable> getNodesTariffStatTable() const;
72  std::shared_ptr<PopTable> getPopTable() const;
73  std::shared_ptr<FuncGroupsTable> getFuncGroupsTable() const;
74  std::shared_ptr<WindfarmsTable> getWindfarmTable() const;
75  std::shared_ptr<FishFarmsDefTable> getFishfarmDefTable() const;
76  std::shared_ptr<MetadataTable> metadata() const;
77 
78  std::shared_ptr<sqlite::SQLiteStorage> getDb() const;
79 
80  void exportFishfarmDef(const Fishfarm &fishfarm);
81  void exportFishfarmLog(Fishfarm *fishfarm, int tstep);
82  void exportWindmillsLog(Windmill *windmill, int tstep);
83  void exportPopNodes(int tstep, Node *node);
84  void exportEnvtNodes(int tstep, Node *node);
85  void exportTariffNodes(int tstep, Node *node);
86  void exportPopStat(Population *pop, int popid, int tstep);
87  void exportPopQuotas(Population *pop, int popid, int tstep);
88  void exportLogLike(Vessel *v, const std::vector<double> &populations, const std::vector<double> &discards, unsigned int tstep);
89  void exportCalendar (const std::vector<int> &tsteps_months, const std::vector<int> &tsteps_quarters,
90  const std::vector<int> &tsteps_semesters, const std::vector<int> &tsteps_years);
91  void exportShip (int tstep, Ship *ship);
92  void importCalendar (std::vector<int> &tsteps_months, std::vector<int> &tsteps_quarters,
93  std::vector<int> &tsteps_semesters, std::vector<int> &tsteps_years);
94 
95  enum Operation { Sum, Average, Count };
96  TimelineData getVesselLoglikeDataByNation(displace::plot::NationsStat stattype, std::string nation, Operation op);
97  TimelineData getVesselLoglikeDataByVessel(displace::plot::VesselsStat stattype, std::string vessel, Operation op);
98  TimelineData getVesselLoglikeDataByHarbour(displace::plot::HarboursStat stattype, int harbourid, Operation op);
99  TimelineData getVesselLoglikeDataByMetier(displace::plot::MetiersStat stattype, int metierid, Operation op);
101  int popid, std::vector<int> szid);
102  TimelineData getBenthosStatData(displace::plot::BenthosStat stattype, displace::plot::AggregationType aggtype, int grpid, const std::vector<int> &btype);
103  TimelineData getShipsStatData(displace::plot::ShipsStat stattype, displace::plot::AggregationType aggtype, int shipid, std::vector<int> shiptypeid);
104  TimelineData getFishFarmStatData(displace::plot::FishfarmsStat stattype, displace::plot::AggregationType aggtype, int ffid, std::vector<int> ftypes);
105 
106  size_t getNbPops();
107 
108  std::vector<std::string> getNationsList();
109  std::vector<std::string> getPopulationsList();
110 private:
111 };
112 
113 #endif // SQLITEOUTPUTSTORAGE_H
VesselsStat
Definition: plottypes.h:20
Definition: sqliteoutputstorage.cpp:40
Definition: funcgroupstable.h:19
Definition: Node.h:39
HarboursStat
Definition: plottypes.h:23
Definition: nodesenvttable.h:20
Definition: sqliteoutputstorage.h:33
Definition: nodesstattable.h:19
int tstep
Definition: main.cpp:205
AggregationType
Definition: plottypes.h:29
Definition: nodesdeftable.h:20
Definition: poptable.h:19
Definition: vesseldeftable.h:20
bool isOutdated()
Definition: sqliteoutputstorage.h:56
Definition: Population.h:34
MetiersStat
Definition: plottypes.h:26
Definition: Windmill.h:4
FishfarmsStat
Definition: plottypes.h:11
Definition: vesselvmslikefpingsonlytable.h:17
Definition: nodestariffstattable.h:19
Definition: vesselvmsliketable.h:17
Definition: windfarmstable.h:17
vector< Population * > populations
Definition: main.cpp:202
Definition: dbtypes.h:7
NationsStat
Definition: plottypes.h:17
Definition: fishfarmsdeftable.h:18
Operation
Definition: sqliteoutputstorage.h:95
Definition: sqliteoutputstorage.h:37
BenthosStat
Definition: plottypes.h:10
PopulationStat
Definition: plottypes.h:7
Definition: vesselslogliketable.h:14
Definition: metadatatable.h:18
Definition: sqliteoutputstorage.h:95
Definition: Fishfarm.h:33
ShipsStat
Definition: plottypes.h:14
#define COMMONSSHARED_EXPORT
Definition: commons_global.h:23