HatchKeeper  0.90
The Free Open-Source Egg Incubation Software
HK_Advanced.cpp
Go to the documentation of this file.
1 /*******************************************************************/
8 #include "../headers/Advanced.h"
9 
12 
15 {
16  float Loss = 0;
17  int A;
18 
19  for(A = 0; A < GetEggCount();A++) {
20  Loss += HK_AdvEggs[A].CalcTotalLoss();
21  }
22 
23  return Loss / A;
24 }
25 
26 
29 {
30  HK_AdvID = -1;
31  HK_AdvUnit = -1;
32  HK_AdvDays = -1;
33  HK_AdvEggs.clear();
34  HK_AdvEggs.shrink_to_fit();
35  HK_AdvUpdate = false;
36 
37 }
38 
40 void HK_Advanced::AddEgg(HK_Egg Egg){HK_AdvEggs.push_back(Egg);}
48 vector<HK_Egg> HK_Advanced::GetEggs(){return HK_AdvEggs;}
50 HK_Egg HK_Advanced::GetEgg(int Select){return HK_AdvEggs[Select];}
52 int HK_Advanced::GetEggCount(){return HK_AdvEggs.size();}
53 
56 {
57  int Fertile = 0;
58 
59  for(int A = 0; A < GetEggCount(); A++)
60  if(HK_AdvEggs[A].GetFertile() == 1)
61  Fertile++;
62  return Fertile;
63 }
66 {
67  int Chicks = 0;
68 
69  for(int A = 0; A < GetEggCount(); A++)
70  if(HK_AdvEggs[A].GetResult() == 0)
71  Chicks++;
72  return Chicks;
73 }
74 
79 
80  string sql = "INSERT INTO Advanced VALUES(" + to_string(GetID()) + "," +
81  to_string(GetEggCount()) + ","+ to_string(GetUnit()) + "," + to_string(GetDays()) + ",";
82 
83  string tag1 = "", tag2 = "", tag3 = "";
84  string fertile = "", pip = "";
85  string result = "", resDate = "", eggCom = "";
86  string dWeight = "", dComment = "";
87  int a, b;
88  HK_Egg Egg;
89  vector<HK_Weight> weights;
90  vector<string> daycomms;
91 
92  for(a = 0;a < (GetEggCount() - 1); a++) {
93  Egg = GetEgg(a);
94  tag1 += Egg.GetTag1() + "&";
95  tag2 += Egg.GetTag2() + "&";
96  tag3 += Egg.GetTag3() + "&";
97  fertile += to_string(Egg.GetFertile()) + "/";
98  pip += to_string(Egg.GetPipped()) + "/";
99  result += to_string(Egg.GetResult()) + "/";
100  resDate += Egg.GetDate().ToSortable("/") + "&";
101  eggCom += Egg.GetComments() + "&";
102 
103  //Day Weight
104  weights = Egg.GetDayWeight();
105  for(b = 0; b < (GetDays() - 1); b++)
106  dWeight += weights[b].GetString() + "/";
107  dWeight += weights[b].GetString() + "&";
108 
109  //Day Comments
110  daycomms = Egg.GetDayComments();
111  for(b = 0; b < (GetDays() - 1); b++) {
112  dComment += daycomms[b] + "|";
113  }
114  dComment += daycomms[b] + "&";
115  }
116 
117  Egg = GetEgg(a);
118  tag1 += Egg.GetTag1();
119  tag2 += Egg.GetTag2();
120  tag3 += Egg.GetTag3();
121  fertile += to_string(Egg.GetFertile());
122  pip += to_string(Egg.GetPipped());
123  result += to_string(Egg.GetResult());
124  resDate += Egg.GetDate().ToSortable("/");
125  eggCom += Egg.GetComments();
126 
127  //Day Weight
128  weights = Egg.GetDayWeight();
129  for(b = 0; b < (GetDays() - 1); b++)
130  dWeight += weights[b].GetString() + "/";
131  dWeight += weights[b].GetString();
132 
133  //Day Comments
134  daycomms = Egg.GetDayComments();
135  for(b = 0; b < (GetDays() - 1); b++)
136  dComment += daycomms[b] + "|";
137  dComment += daycomms[b];
138 
139  //Add Tags
140  sql += "'" + tag1 + "','" + tag2 + "','" + tag3 + "','";
141  //Fertile & Pipped
142  sql += fertile + "','" + pip + "','";
143  //Result and comments
144  sql += result + "','" + resDate + "','" + eggCom + "','";
145  //Day weight and comments
146  sql += dWeight + "','" + dComment + "');";
147 
148  return sql;
149 }
150 
152 vector<string> HK_Advanced::GetUpdate()
153 {
154  int A = 0,B = 0,Fertile = 0,Chicks = 0;
155  vector<string> Sql, Results;
156 
157  Sql.push_back(" EggComments = '");
158  Sql.push_back(" Tag1 = '");
159  Sql.push_back(" Tag2 = '");
160  Sql.push_back(" Tag3 = '");
161  Sql.push_back(" Fertile = '");
162  Sql.push_back(" Pipped = '");
163  Sql.push_back(" Result = '");
164  Sql.push_back(" ResultDate = '");
165  Sql.push_back(" DayWeight = '");
166  Sql.push_back(" DayComment = '");
167 
168  //Values
169  for(A = 0;A < (GetEggCount() - 1); A++) {
170  Sql[0] += HK_AdvEggs[A].GetComments() + "&";
171 
172  Sql[1] += HK_AdvEggs[A].GetTag1() + "&";
173  Sql[2] += HK_AdvEggs[A].GetTag2() + "&";
174  Sql[3] += HK_AdvEggs[A].GetTag3() + "&";
175 
176  Sql[4] += to_string(HK_AdvEggs[A].GetFertile()) + "/";
177  Fertile += HK_AdvEggs[A].GetFertile();
178 
179  Sql[5] += to_string(HK_AdvEggs[A].GetPipped()) + "/";
180 
181  Sql[6] += to_string(HK_AdvEggs[A].GetResult()) + "/";
182  if(HK_AdvEggs[A].GetResult() == 0)
183  Chicks++;
184 
185  Sql[7] += HK_AdvEggs[A].GetDate().ToSortable("/") + "&";
186 
187  for(B = 0; B < (GetDays() - 1); B++)
188  Sql[8] += to_string(HK_AdvEggs[A].GetDayWeight()[B].GetFloat()) + "/";
189  Sql[8] += HK_AdvEggs[A].GetDayWeight()[B].GetString() + "&";
190 
191  for(B = 0; B < (GetDays() - 1); B++)
192  Sql[9] += HK_AdvEggs[A].GetDayComments()[B] + "|";
193  Sql[9] += HK_AdvEggs[A].GetDayComments()[B] + "&";
194  }
195 
196  Sql[0] += HK_AdvEggs[A].GetComments();
197  Sql[1] += HK_AdvEggs[A].GetTag1();
198  Sql[2] += HK_AdvEggs[A].GetTag2();
199  Sql[3] += HK_AdvEggs[A].GetTag3();
200 
201  Sql[4] += to_string(HK_AdvEggs[A].GetFertile());
202  Fertile += HK_AdvEggs[A].GetFertile();
203 
204  Sql[5] += to_string(HK_AdvEggs[A].GetPipped());
205 
206  Sql[6] += to_string(HK_AdvEggs[A].GetResult());
207  if(HK_AdvEggs[A].GetResult() == 0)
208  Chicks++;
209 
210  Sql[7] += HK_AdvEggs[A].GetDate().ToSortable("/");
211 
212  for(B = 0; B < (GetDays() - 1); B++)
213  Sql[8] += HK_AdvEggs[A].GetDayWeight()[B].GetString() + "/";
214  Sql[8] += HK_AdvEggs[A].GetDayWeight()[B].GetString();
215 
216  for(B = 0; B < (GetDays() - 1); B++)
217  Sql[9] += HK_AdvEggs[A].GetDayComments()[B] + "|";
218  Sql[9] += HK_AdvEggs[A].GetDayComments()[B];
219 
220  //Add ID
221  string Temp = "UPDATE Advanced SET ";
222  unsigned int C = 0;
223  for(C = 0; C < Sql.size() - 1; C++)
224  Temp += Sql[C] + "', ";
225  Temp += Sql[C] + "' WHERE ID = " + to_string(HK_AdvID) + ";";
226 
227  //Update Batch As Well
228  Results.push_back(" UPDATE Batches SET FertileEggs = " + to_string(Fertile) + " WHERE ID = " + to_string(HK_AdvID) + ";");
229  Results.push_back(" UPDATE Batches SET ChicksHatched = " + to_string(Chicks) + " WHERE ID = " + to_string(HK_AdvID) + ";");
230  Results.push_back(Temp);
231 
232  return Results;
233 }
234 
237 
239 HK_KeyValue HK_Advanced::Search(string Value, string BatchName)
240 {
241  HK_KeyValue Results;
242 
243  for(int A = 0; A < GetEggCount(); A++)
244  Results.Add(HK_AdvEggs[A].Search(Value,BatchName,(A + 1)));
245 
246  return Results;
247 }
248 
250 void HK_Advanced::Set(int ID, int Unit, int Days, vector<HK_Egg> Eggs)
251 {
252  HK_AdvID = ID;
253  HK_AdvUnit = Unit;
254  HK_AdvDays = Days;
255  HK_AdvEggs = Eggs;
256 }
257 
259 void HK_Advanced::SetID(int ID){HK_AdvID = ID;}
261 void HK_Advanced::SetUnit(int Unit){HK_AdvUnit = Unit;}
263 void HK_Advanced::SetDays(int Days){HK_AdvDays = Days;}
265 void HK_Advanced::SetEggs(vector<HK_Egg> Eggs){HK_AdvEggs = Eggs;}
267 void HK_Advanced::SetEgg(HK_Egg Egg, int Select){HK_AdvEggs[Select] = Egg;}
269 void HK_Advanced::SetUpdate(bool Status){HK_AdvUpdate = Status;}
HK_Egg GetEgg(int Select)
Returns The Selected Egg.
Definition: HK_Advanced.cpp:50
int GetEggCount()
Returns The Number Of Eggs.
Definition: HK_Advanced.cpp:52
void SetEggs(vector< HK_Egg > Eggs)
Sets All Eggs At Once.
vector< HK_Egg > HK_AdvEggs
Definition: Advanced.h:25
void SetUpdate(bool Status)
Sets Update Status For This HK_Advanced.
HK_KeyValue Search(string Value, string BatchName)
Searches Eggs For Matches To Value.
vector< string > GetUpdate()
Returns An Array Of SQL Strings To Update Database.
void AddEgg(HK_Egg Egg)
Adds An HK_Egg To HK_AdvEggs Vector.
Definition: HK_Advanced.cpp:40
string GetSQL()
Definition: HK_Advanced.cpp:78
bool HK_AdvUpdate
Definition: Advanced.h:27
int GetChicks()
Returns The Number Of Eggs That Hatched Based On HK_Egg Data.
Definition: HK_Advanced.cpp:65
int GetDays()
Returns Incubation Days.
Definition: HK_Advanced.cpp:46
int HK_AdvDays
Definition: Advanced.h:24
void SetID(int ID)
Sets ID.
HK_Advanced()
Default Constructor.
Definition: HK_Advanced.cpp:11
int CalcAvgLoss()
Returns The Average Weight Loss For All Eggs In Batch.
Definition: HK_Advanced.cpp:14
void Clear()
Clears All Data From This Object.
Definition: HK_Advanced.cpp:28
int HK_AdvID
Definition: Advanced.h:22
void SetEgg(HK_Egg Egg, int Select)
Sets Selected Egg.
int HK_AdvUnit
Definition: Advanced.h:23
int GetFertile()
Returns The Number Of Eggs That Are Fertile Based On HK_Egg Data.
Definition: HK_Advanced.cpp:55
void SetUnit(int Unit)
Sets Weight Unit Used.
void SetDays(int Days)
Sets Incubation Days.
int GetUnit()
Returns Weight Unit.
Definition: HK_Advanced.cpp:44
bool GetUpdateStatus()
Returns True If This HK_Advanced Has Data That Needs To Be Updated.
int GetID()
Returns ID.
Definition: HK_Advanced.cpp:42
void Set(int ID, int Unit, int Days, vector< HK_Egg > Eggs)
Initialize In One Function Call.
vector< HK_Egg > GetEggs()
Returns An Array Of HK_Egg Objects.
Definition: HK_Advanced.cpp:48
std::string ToSortable(std::string Separator)
Generate A Sortable String For Database.
Definition: HK_Date.cpp:163
A Class For Storing And Retieving Data For One Egg.
Definition: Egg.h:24
int GetResult()
Returns -1 If No Result, 0 If Hatched, And 2 If Egg Quit.
Definition: HK_Egg.cpp:58
string GetComments()
Returns Egg Comments.
Definition: HK_Egg.cpp:64
string GetTag2()
Returns Tag 2 As A String.
Definition: HK_Egg.cpp:50
HK_Date GetDate()
Returns The Date For The Result.
Definition: HK_Egg.cpp:60
string GetTag3()
Returns Tag 3 As A String.
Definition: HK_Egg.cpp:52
vector< string > GetDayComments()
Returns An Array Containing A Comment For Every Day.
Definition: HK_Egg.cpp:68
vector< HK_Weight > GetDayWeight()
Returns An Array Containing A Weight For Every Day.
Definition: HK_Egg.cpp:66
int GetPipped()
Returns 0 If Egg Is Not Pipped And 1 If It Is.
Definition: HK_Egg.cpp:56
string GetTag1()
Returns Tag 1 As A String.
Definition: HK_Egg.cpp:48
int GetFertile()
Returns 0 If Egg Is Not Fertile And 1 If It Is.
Definition: HK_Egg.cpp:54
A Key and Value Type Storage.
Definition: KeyValue.h:25
void Add(string Key, string Value)
Adds A Key And Value;.
Definition: HK_KeyValue.cpp:33