Add files via upload

master
呓喵酱 5 years ago committed by GitHub
parent b2c6acac41
commit 83c1601d26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      src/car.cpp
  2. 165
      src/car.h
  3. 140
      src/feeTable.cpp
  4. 245
      src/feeTable.h
  5. 375
      src/main.cpp
  6. 497
      src/park.cpp
  7. 1150
      src/park.h
  8. 31
      src/plot.cpp
  9. 163
      src/plot.h

@ -0,0 +1,32 @@
/*
* @Author: IoTcat (https://iotcat.me)
* @Date: 2019-05-24 17:01:37
* @Last Modified by: IoTcat
* @Last Modified time: 2019-05-24 17:01:37
*/
#include "car.h"
Car::Car(const string& licenseNum, const string& type, const string& plot) {
this->_d["id"] = licenseNum;
this->_d["type"] = type;
this->_d["plot"] = plot;
this->_d["LastInTime"] = to_string(time(NULL));
this->_d["LastOutTime"] = "null";
this->_isExist = true;
}
Car::Car(const string& s) {
this->_isExist = false;
if (s == "undefined") {
return;
}
this->_d = this->_d.strToData(s);
if (this->_d["id"] == "undefined") return;
this->_isExist = true;
}

@ -1,96 +1,71 @@
#ifndef __CAR_H__
#define __CAR_H__
#include <iostream>
#include <vector>
#include <string>
#include "../lib/ovo.h"
using namespace std;
class Car{
public:
Car(const string& licenseNum, const string& type, const string& plot){
this->_d["id"] = licenseNum;
this->_d["type"] = type;
this->_d["plot"] = plot;
this->_d["LastInTime"] = to_string(time(NULL));
this->_d["LastOutTime"] = "null";
this->_isExist = true;
};
Car(const string& s){
this->_isExist = false;
if(s == "undefined"){
return;
}
this->_d = this->_d.strToData(s);
if(this->_d["id"] == "undefined") return;
this->_isExist = true;
};
Car(){
this->_isExist = false;
};
~Car(){
};
inline bool isExist(){
return this->_isExist;
};
inline string getID(){
return this->_d["id"];
};
inline string getType(){
return this->_d["type"];
};
inline string getLastInTime(){
return this->_d["LastInTime"];
};
inline string getLastOutTime(){
return this->_d["LastOutTime"];
};
inline string getPlot(){
return this->_d["plot"];
};
inline string showAll(){
return this->_d.showAll();
};
inline string getDataStr(){
this->_d.classify();
return this->_d.dataToStr(this->_d);
};
private:
ovo::data _d;
bool _isExist;
};
/*
* @Author: IoTcat (https://iotcat.me)
* @Date: 2019-05-24 17:01:44
* @Last Modified by: IoTcat
* @Last Modified time: 2019-05-24 17:01:44
*/
#ifndef __CAR_H__
#define __CAR_H__
#include <iostream>
#include <vector>
#include <string>
#include "../lib/ovo.h"
using namespace std;
class Car{
public:
Car(const string& licenseNum, const string& type, const string& plot);
Car(const string& s);
Car(){
this->_isExist = false;
};
~Car(){};
inline const bool isExist() const{
return this->_isExist;
};
inline const string getID(){
return this->_d["id"];
};
inline const string getType(){
return this->_d["type"];
};
inline const string getLastInTime(){
return this->_d["LastInTime"];
};
inline const string getLastOutTime(){
return this->_d["LastOutTime"];
};
inline const string getPlot(){
return this->_d["plot"];
};
inline const string showAll(){
return this->_d.showAll();
};
inline const string getDataStr(){
this->_d.classify();
return this->_d.dataToStr(this->_d);
};
private:
ovo::data _d;
bool _isExist;
};
#endif //__CAR_H__

@ -0,0 +1,140 @@
/*
* @Author: IoTcat (https://iotcat.me)
* @Date: 2019-05-24 17:01:34
* @Last Modified by: IoTcat
* @Last Modified time: 2019-05-24 17:01:34
*/
#include "feeTable.h"
FeeTable::FeeTable() {
this->_d.clear();
this->_d = db.getData(g_feeTableID);
this->_tableData = db.getData(g_feeTableID + "_Table");
this->_tableData.forEach([&](string first, string second) {
this->_table[first] = this->_vecFromStr(second);
});
};
FeeTable::~FeeTable() {
this->_d.classify();
db.pushData(g_feeTableID, this->_d);
this->_pushTable();
db.pushData(g_feeTableID + "_Table", this->_tableData);
};
void FeeTable::setTypes(std::vector<string>& v) {
std::vector<int> vv;
vv = this->_classify(vv);
this->_table.erase(this->_table.begin(), this->_table.end());
for (auto i : v) {
this->_table[i] = vv;
}
}
void FeeTable::set(std::map<string, std::vector<int>>& m) {
for (auto& i : m) {
if (this->_table.count(i.first)) {
this->_table[i.first].erase(this->_table[i.first].begin(),
this->_table[i.first].end());
this->_table[i.first] = this->_classify(i.second);
}
}
}
int const FeeTable::getFee(const string& type, const string& LastInTime,
const string& LastOutTime) {
if (!this->_table.count(type)) return -1;
int t = atoi(LastOutTime.c_str()) - atoi(LastInTime.c_str());
t /= 3600;
int days = t / 24;
int hours = t % 24;
int fee = 0;
for (int i = 0; i <= hours; i++) {
fee += this->_table[type][i];
}
int DailyFee = 0;
for (int i : this->_table[type]) {
DailyFee += i;
}
fee += days * DailyFee;
return fee;
}
const string FeeTable::showAll() const {
string s = "{\n";
for (auto i : this->_table) {
s += " \"" + i.first + "\": [";
for (auto ii : i.second) {
s += to_string(ii) + ", ";
}
s += "],\n";
}
s += "}";
return s;
}
const std::vector<int> FeeTable::_classify(std::vector<int>& v) const {
std::vector<int> o;
if (v.size() < 24) {
for (int i : v) {
o.push_back(i);
}
for (int i = 0; i < 24 - v.size(); i++) {
o.push_back(0);
}
} else {
for (int i = 0; i < 24; i++) {
o.push_back(v[i]);
}
}
return o;
}
const string FeeTable::_vecToStr(std::vector<int>& v) const {
string s = "";
for (int i : v) {
s += to_string(i) + "|||$$|||";
}
return s;
}
const std::vector<int> FeeTable::_vecFromStr(const string& s) {
std::vector<string> v;
S.split(s, v, "|||$$|||");
std::vector<int> o;
for (string i : v) {
o.push_back(atoi(i.c_str()));
}
return o;
}
void FeeTable::_pushTable() {
this->_tableData.clear();
for (auto i : this->_table) {
this->_tableData[i.first] = this->_vecToStr(i.second);
}
}

@ -1,190 +1,55 @@
#ifndef __FEETABLE_H__
#define __FEETABLE_H__
#include <iostream>
#include <vector>
#include <string>
#include "../lib/ovo.h"
const string g_feeTableID = "__Fee_Table__AS4";
using namespace std;
class FeeTable{
public:
FeeTable(){
this->_d.clear();
this->_d = db.getData(g_feeTableID);
this->_tableData = db.getData(g_feeTableID + "_Table");
this->_tableData.forEach([&](string first, string second){
this->_table[first] = this->_vecFromStr(second);
});
};
~FeeTable(){
this->_d.classify();
db.pushData(g_feeTableID, this->_d);
this->_pushTable();
db.pushData(g_feeTableID + "_Table", this->_tableData);
};
void setTypes(std::vector<string> v){
std::vector<int> vv;
vv = this->_classify(vv);
this->_table.erase(this->_table.begin(), this->_table.end());
for(auto i : v){
this->_table[i] = vv;
}
}
void set(std::map<string, std::vector<int>>& m){
for(auto& i : m){
if(this->_table.count(i.first)){
this->_table[i.first].erase(this->_table[i.first].begin(), this->_table[i.first].end());
this->_table[i.first] = this->_classify(i.second);
}
}
}
inline std::map<string, std::vector<int>> getTable(){
return this->_table;
}
inline std::vector<int> getTable(const string& type){
if(this->_table.count(type)){
return this->_table[type];
}
return std::vector<int>();
}
int getFee(const string& type, const string& LastInTime, const string& LastOutTime){
if(!this->_table.count(type)) return -1;
int t = atoi(LastOutTime.c_str()) - atoi(LastInTime.c_str());
t /= 3600;
int days = t / 24;
int hours = t % 24;
int fee = 0;
for(int i = 0; i <= hours; i ++){
fee += this->_table[type][i];
}
int DailyFee = 0;
for(int i : this->_table[type]){
DailyFee += i;
}
fee += days * DailyFee;
return fee;
}
string showAll(){
string s = "{\n";
for(auto i : this->_table){
s += " \"" + i.first + "\": [";
for(auto ii : i.second){
s += to_string(ii) + ", ";
}
s += "],\n";
}
s += "}";
return s;
}
//private:
ovo::data _d, _tableData;
ovo::db db;
ovo::String S;
std::map<string, std::vector<int>> _table;
std::vector<int> _classify(std::vector<int>& v){
std::vector<int> o;
if(v.size() < 24){
for(int i : v){
o.push_back(i);
}
for(int i = 0; i < 24 - v.size(); i ++){
o.push_back(0);
}
}else{
for(int i = 0; i < 24; i ++){
o.push_back(v[i]);
}
}
return o;
}
string _vecToStr(std::vector<int>& v){
string s = "";
for(int i : v){
s += to_string(i) + "|||$$|||";
}
return s;
}
std::vector<int> _vecFromStr(const string& s){
std::vector<string> v;
S.split(s, v, "|||$$|||");
std::vector<int> o;
for(string i : v){
o.push_back(atoi(i.c_str()));
}
return o;
}
void _pushTable(){
this->_tableData.clear();
for(auto i : this->_table){
this->_tableData[i.first] = this->_vecToStr(i.second);
}
}
};
#endif //__FEETABLE_H__
/*
* @Author: IoTcat (https://iotcat.me)
* @Date: 2019-05-24 17:01:28
* @Last Modified by: IoTcat
* @Last Modified time: 2019-05-24 17:01:28
*/
#ifndef __FEETABLE_H__
#define __FEETABLE_H__
#include <iostream>
#include <string>
#include <vector>
#include "../lib/ovo.h"
const string g_feeTableID = "__Fee_Table__AS4";
using namespace std;
class FeeTable {
public:
FeeTable();
~FeeTable();
void setTypes(std::vector<string>& v);
void set(std::map<string, std::vector<int>>& m);
int const getFee(const string& type, const string& LastInTime,
const string& LastOutTime);
const string showAll() const;
inline const std::map<string, std::vector<int>> getTable() const {
return this->_table;
};
inline const std::vector<int> getTable(const string& type) {
if (this->_table.count(type)) {
return this->_table[type];
}
return std::vector<int>();
};
private:
ovo::data _d, _tableData;
ovo::db db;
ovo::String S;
std::map<string, std::vector<int>> _table;
const std::vector<int> _classify(std::vector<int>& v) const;
const string _vecToStr(std::vector<int>& v) const;
const std::vector<int> _vecFromStr(const string& s);
void _pushTable();
};
#endif //__FEETABLE_H__

@ -1,193 +1,184 @@
#include <iostream>
#include <vector>
#include <map>
#include <ctime>
#include "park.h"
#include "../lib/ovo.h"
using namespace std;
int main(int argc, char const *argv[])
{
Park p;
if(!p.isExist()){
ovo::math m;
std::vector<std::map<string, int>> ParkIniInfo;
std::map<string, int> t_map;
for(int i = 0; i < 100; i ++){
t_map["Car"] = m.rand(0, 600);
t_map["Bicycle"] = m.rand(0, 600);
t_map["Airplane"] = m.rand(0, 600);
t_map["Ship"] = m.rand(0, 600);
ParkIniInfo.push_back(t_map);
}
p.ini(ParkIniInfo);
std::map<string, std::vector<int>> feeTable;
std::vector<int> fee;
for(int i = 0; i < 24; i ++){
fee.push_back(m.rand(0, 60));
}
feeTable["Car"] = fee;
for(int i = 0; i < 24; i ++){
fee[i] = m.rand(0, 60);
}
feeTable["Bicycle"] = fee;
for(int i = 0; i < 24; i ++){
fee[i] = m.rand(0, 60);
}
feeTable["Airplane"] = fee;
for(int i = 0; i < 24; i ++){
fee[i] = m.rand(0, 60);
}
feeTable["Ship"] = fee;
p.updateFeeTable(feeTable);
}
ovo::data d;
d["date"] = "2019-05-24";
cout <<p.getLog(d).size();
//cout << p.getLog()
while(1){
string input = "";
while(cin >> input){
if(input == "getPlots"){
for(auto i : p.getPlotsID()){
cout << p.getPlot(i).showAll() << endl;
}
}
if(input == "getPlotsNum"){
cout << p.getPlotsID().size() << endl;
}
input = "";
}
}
// FeeTable t;
/*
std::vector<string> v;
v.push_back("Cars");
v.push_back("rac");
t.setTypes(v);
*//*
std::map<string, std::vector<int>> mm;
std::vector<int> vv;
vv.push_back(2);
vv.push_back(3);
mm["Cars"] = vv;
t.set(mm);
cout << t.showAll();
//t.set(m);
//cout << t.getFee("car", "0", "10000");
//cout << t.showAll();
*/
/*
Plot p("eeeee", 3, "222");
ovo::data d;
d["eeeee"] = p.getStrContent();
cout << d.showAll();
*/
/*
Park p;
//cout << p.isExist();
std::vector<map<string, int>> v;
map<string, int> m;
m["Bycycle"] = 599;
m["Cars"] = 2;
v.push_back(m);
m["Carsss"] = 99;
v.push_back(m);
p.ini(v);
//p.updateFeeTable(mm);
//cout << p.checkType("Cadrs");
p.join();
p.checkIn("2333", "Cars");
cout << p.checkOut("2333");
//cout << p._feeTable.showAll();
//cout << p._d.showAll();
//*/
/*
string kk = "";
if(!p.newCar("110", "Cars", p.getPlotsID("Cars", false)[0], kk))cout << kk;
int t = time(NULL);
string s = "Cars";
//cout << endl<<p.getPlotsID("Cars", false).size();
for(auto i : p.getPlotsID(s)){
cout << p.getPlot(i).showAll();
}/*
for(auto i : p.getCarsID(0)){
cout << i;
}
cout << " " << time(NULL) - t;
//p.delCar("110");
cout << p.getPlotByCar("110").showAll();
for(auto i : p.getLogByDate("2019-05-23")){
cout << i.showAll();
}
*/
return 0;
#include <ctime>
#include <iostream>
#include <map>
#include <vector>
#include "park.h"
#include "../lib/ovo.h"
using namespace std;
int main(int argc, char const *argv[]) {
Park p;
if (!p.isExist()) {
ovo::math m;
std::vector<std::map<string, int>> ParkIniInfo;
std::map<string, int> t_map;
for (int i = 0; i < 100; i++) {
t_map["Car"] = m.rand(0, 600);
t_map["Bicycle"] = m.rand(0, 600);
t_map["Airplane"] = m.rand(0, 600);
t_map["Ship"] = m.rand(0, 600);
ParkIniInfo.push_back(t_map);
}
p.ini(ParkIniInfo);
std::map<string, std::vector<int>> feeTable;
std::vector<int> fee;
for (int i = 0; i < 24; i++) {
fee.push_back(m.rand(0, 60));
}
feeTable["Car"] = fee;
for (int i = 0; i < 24; i++) {
fee[i] = m.rand(0, 60);
}
feeTable["Bicycle"] = fee;
for (int i = 0; i < 24; i++) {
fee[i] = m.rand(0, 60);
}
feeTable["Airplane"] = fee;
for (int i = 0; i < 24; i++) {
fee[i] = m.rand(0, 60);
}
feeTable["Ship"] = fee;
p.updateFeeTable(feeTable);
}
ovo::data d;
d["date"] = "2019-05-24";
cout << p.getLog(d)[0].showAll();
// cout << p.getLog()
while (1) {
string input = "";
while (cin >> input) {
if (input == "getPlots") {
for (auto i : p.getPlotsID()) {
cout << p.getPlot(i).showAll() << endl;
}
}
if (input == "getPlotsNum") {
cout << p.getPlotsID().size() << endl;
}
input = "";
}
}
// FeeTable t;
/*
std::vector<string> v;
v.push_back("Cars");
v.push_back("rac");
t.setTypes(v);
*//*
std::map<string, std::vector<int>> mm;
std::vector<int> vv;
vv.push_back(2);
vv.push_back(3);
mm["Cars"] = vv;
t.set(mm);
cout << t.showAll();
//t.set(m);
//cout << t.getFee("car", "0", "10000");
//cout << t.showAll();
*/
/*
Plot p("eeeee", 3, "222");
ovo::data d;
d["eeeee"] = p.getStrContent();
cout << d.showAll();
*/
/*
Park p;
//cout << p.isExist();
std::vector<map<string, int>> v;
map<string, int> m;
m["Bycycle"] = 599;
m["Cars"] = 2;
v.push_back(m);
m["Carsss"] = 99;
v.push_back(m);
p.ini(v);
//p.updateFeeTable(mm);
//cout << p.checkType("Cadrs");
p.join();
p.checkIn("2333", "Cars");
cout << p.checkOut("2333");
//cout << p._feeTable.showAll();
//cout << p._d.showAll();
//*/
/*
string kk = "";
if(!p.newCar("110", "Cars", p.getPlotsID("Cars", false)[0], kk))cout <<
kk;
int t = time(NULL);
string s = "Cars";
//cout << endl<<p.getPlotsID("Cars", false).size();
for(auto i : p.getPlotsID(s)){
cout << p.getPlot(i).showAll();
}/*
for(auto i : p.getCarsID(0)){
cout << i;
}
cout << " " << time(NULL) - t;
//p.delCar("110");
cout << p.getPlotByCar("110").showAll();
for(auto i : p.getLogByDate("2019-05-23")){
cout << i.showAll();
}
*/
return 0;
}

@ -0,0 +1,497 @@
/*
* @Author: IoTcat (https://iotcat.me)
* @Date: 2019-05-24 17:01:26
* @Last Modified by: IoTcat
* @Last Modified time: 2019-05-24 17:01:26
*/
#include "park.h"
Park::Park() {
this->_threadFinished = true;
this->_threadPointer = false;
this->_d = db.getData(g_ParkID);
if (!this->isExist()) return;
this->_threadFinished = false;
this->_t = new std::thread([&] {
this->_threadPointer = true;
this->_plotsList = db.getData(this->_d["plotsList"]);
this->_carsList = db.getData(this->_d["carsList"]);
this->_recoverTypes();
this->_levels = atoi(this->_d["levels"].c_str());
this->_threadFinished = true;
});
};
Park::~Park() {
if (!this->_threadFinished) this->_t->join();
this->_d.classify();
this->_plotsList.classify();
this->_carsList.classify();
db.pushData(g_ParkID, this->_d);
db.pushData(this->_d["plotsList"], this->_plotsList);
db.pushData(this->_d["carsList"], this->_carsList);
};
void Park::join() {
if (!this->_threadFinished) {
this->_t->join();
delete this->_t;
this->_threadPointer = false;
this->_threadFinished = true;
}
if (this->_threadPointer) {
delete this->_t;
this->_threadPointer = false;
}
}
void Park::ini(std::vector<std::map<string, int>>& v) {
if (!this->_threadFinished) this->_t->join();
this->_d.clear();
this->_plotsList.clear();
this->_carsList.clear();
this->_getTypes(v);
this->_levels = v.size();
this->_d["id"] = g_ParkID;
this->_d["carsList"] = m.randStr();
this->_d["plotsList"] = m.randStr();
this->_d["feeTable"] = m.randStr();
this->_d["log"] = m.randStr();
this->_d["levels"] = to_string(this->_levels);
this->_d["types"] = "";
for (string i : this->_types) {
this->_d["types"] += i + "|||$$|||";
}
this->_setupPlots(v);
this->_feeTable.setTypes(this->_types);
std::vector<string> vv;
vv.push_back("uid");
vv.push_back("licenseNum");
vv.push_back("type");
vv.push_back("level");
vv.push_back("plot");
vv.push_back("LastInTime");
vv.push_back("LastOutTime");
vv.push_back("fee");
vv.push_back("date");
db.createTable(this->_d["log"], vv);
};
const vector<string> Park::getPlotsID() {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
this->_plotsList.forEach(
[&](string first, string second) { v.push_back(first); });
return v;
};
const std::vector<string> Park::getPlotsID(const bool& isOccupied) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
this->_plotsList.forEach([&](string first, string second) {
if (isOccupied && this->_simpleGet(second, "car") != "null")
v.push_back(first);
if (!isOccupied && this->_simpleGet(second, "car") == "null")
v.push_back(first);
});
return v;
};
const std::vector<string> Park::getPlotsID(const int& level) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
this->_plotsList.forEach([&](string first, string second) {
if (this->_simpleGet(second, "level") == to_string(level))
v.push_back(first);
});
return v;
};
const std::vector<string> Park::getPlotsID(const string& type) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
this->_plotsList.forEach([&](string first, string second) {
if (this->_simpleGet(second, "type") == type) v.push_back(first);
});
return v;
};
const std::vector<string> Park::getPlotsID(const int& level,
const bool& isOccupied) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
this->_plotsList.forEach([&](string first, string second) {
if (isOccupied && this->_simpleGet(second, "car") != "null" &&
this->_simpleGet(second, "level") == to_string(level))
v.push_back(first);
if (!isOccupied && this->_simpleGet(second, "car") == "null" &&
this->_simpleGet(second, "level") == to_string(level))
v.push_back(first);
});
return v;
};
const std::vector<string> Park::getPlotsID(const string& type,
const bool& isOccupied) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
this->_plotsList.forEach([&](string first, string second) {
if (isOccupied && this->_simpleGet(second, "car") != "null" &&
this->_simpleGet(second, "type") == type)
v.push_back(first);
if (!isOccupied && this->_simpleGet(second, "car") == "null" &&
this->_simpleGet(second, "type") == type)
v.push_back(first);
});
return v;
};
const std::vector<string> Park::getPlotsID(const int& level,
const string& type) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
this->_plotsList.forEach([&](string first, string second) {
if (this->_simpleGet(second, "level") == to_string(level) &&
this->_simpleGet(second, "type") == type)
v.push_back(first);
});
return v;
};
const std::vector<string> Park::getPlotsID(const int& level, const string& type,
const bool& isOccupied) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
this->_plotsList.forEach([&](string first, string second) {
if (isOccupied && this->_simpleGet(second, "car") != "null" &&
this->_simpleGet(second, "level") == to_string(level) &&
this->_simpleGet(second, "type") == type)
v.push_back(first);
if (!isOccupied && this->_simpleGet(second, "car") == "null" &&
this->_simpleGet(second, "level") == to_string(level) &&
this->_simpleGet(second, "type") == type)
v.push_back(first);
});
return v;
};
Plot Park::getPlot(const string& id) {
if (!this->_threadFinished) this->_t->join();
if (this->_plotsList[id] == "undefined") {
return Plot();
}
return Plot(this->_plotsList[id]);
};
Plot Park::getPlotByCar(const string& licenseNum) {
if (!this->_threadFinished) this->_t->join();
if (this->_carsList[licenseNum] == "undefined") {
return Plot();
}
return Plot(this->_plotsList[this->_simpleGet(this->_carsList[licenseNum],
"plot")]);
};
Plot Park::getPlotByCar(Car& car) {
if (!this->_threadFinished) this->_t->join();
if (this->_carsList[car.getID()] == "undefined") {
return Plot();
}
return Plot(this->_plotsList[this->_simpleGet(this->_carsList[car.getID()],
"plot")]);
};
const bool Park::newCar(const string& licenseNum, const string& type,
const string& plotID, string& msg) {
if (!this->_threadFinished) this->_t->join();
if (licenseNum.length() < 1) {
msg += "Car " + licenseNum + " LicenseNum Illegal!!!";
return false;
}
if (this->_carsList.isExist(licenseNum)) {
msg += "Car " + licenseNum + " Already in the Park!!";
return false;
}
if (this->isGoodType(type)) {
msg += "Car " + licenseNum + " Wrong Type!!!";
return false;
}
if (this->_plotsList[plotID] == "undefined") {
msg += "Car " + licenseNum + " Assigned Plot Not Exist!!!";
return false;
}
Car c(licenseNum, type, plotID);
this->_carsList[licenseNum] = c.getDataStr();
this->_plotsList[plotID] =
this->_simpleUpdate(this->_plotsList[plotID], "car", licenseNum);
return true;
};
const bool Park::delCar(const string& licenseNum, string& msg) {
if (!this->_threadFinished) this->_t->join();
if (!this->_carsList.isExist(licenseNum)) {
msg += "Car " + licenseNum + " Not In Plot!!!";
return false;
}
Car c(this->_carsList[licenseNum]);
this->_plotsList[c.getPlot()] =
this->_simpleUpdate(this->_plotsList[c.getPlot()], "car", "null");
this->_carsList.clear(licenseNum);
return true;
}
const std::vector<string> Park::getCarsID() {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
this->_carsList.forEach(
[&](string first, string second) { v.push_back(first); });
return v;
};
const std::vector<string> Park::getCarsID(const int& level) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
v = this->getPlotsID(level, true);
for (string& i : v) {
i = this->_simpleGet(this->_plotsList[i], "car");
}
return v;
};
const std::vector<string> Park::getCarsID(const string& type) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
v = this->getPlotsID(type, true);
for (string& i : v) {
i = this->_simpleGet(this->_plotsList[i], "car");
}
return v;
};
const std::vector<string> Park::getCarsID(const int& level,
const string& type) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v;
v = this->getPlotsID(level, type, true);
for (string& i : v) {
i = this->_simpleGet(this->_plotsList[i], "car");
}
return v;
};
const bool Park::updatePlot(Plot& plot, const int& level) {
if (!this->_threadFinished) this->_t->join();
if (level < 0 || level > this->_levels) {
return false;
}
this->_plotsList[plot.getID()] = this->_simpleUpdate(
this->_plotsList[plot.getID()], "level", to_string(level));
plot.updateLevel(level);
return true;
}
const bool Park::updatePlot(Plot& plot, const string& type) {
if (!this->_threadFinished) this->_t->join();
if (!this->isGoodType(type)) {
return false;
}
this->_plotsList[plot.getID()] =
this->_simpleUpdate(this->_plotsList[plot.getID()], "type", type);
plot.updateType(type);
return true;
}
const bool Park::checkIn(const string& licenseNum, const string& type,
string& msg) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v = this->getPlotsID(type, false);
if (!v.size()) {
msg += type + " has no more Plots!!";
return false;
}
if (!newCar(licenseNum, type, v[0], msg)) return false;
return true;
}
const bool Park::checkIn(const string& licenseNum, const string& type,
const int& level, string& msg) {
if (!this->_threadFinished) this->_t->join();
std::vector<string> v = this->getPlotsID(level, type, false);
if (!v.size()) {
msg += type + " on Level " + to_string(level) + " has no more Plots!!";
return false;
}
if (!newCar(licenseNum, type, v[0], msg)) return false;
return true;
}
const bool Park::checkInByPlotID(const string& licenseNum, const string& type,
const string& plotID, string& msg) {
if (!this->_threadFinished) this->_t->join();
if (!newCar(licenseNum, type, plotID, msg)) return false;
return true;
}
int Park::checkOut(const string& licenseNum) {
if (!this->_threadFinished) this->_t->join();
if (!this->_carsList.isExist(licenseNum)) return -1;
this->_carsList[licenseNum] = this->_simpleUpdate(
this->_carsList[licenseNum], "LastOutTime", to_string(time(NULL)));
Car c(this->_carsList[licenseNum]);
int fee = this->_feeTable.getFee(c.getType(), c.getLastInTime(),
c.getLastOutTime());
// this->_threadFinished = false;
// this->_t = new std::thread([&]{
// this->_threadPointer = true;
ovo::data d;
d["uid"] = m.randStr();
d["licenseNum"] = licenseNum;
d["type"] = c.getType();
d["plot"] = c.getPlot();
d["level"] = this->_simpleGet(this->_plotsList[c.getPlot()], "level");
d["LastInTime"] = c.getLastInTime();
d["LastOutTime"] = c.getLastOutTime();
d["fee"] = to_string(fee);
d["date"] = this->_getDate();
db.insertSQL(this->_d["log"], d);
this->delCar(licenseNum);
// this->_threadFinished = true;
//});
return fee;
}
void Park::_getTypes(std::vector<std::map<string, int>>& v) {
this->_types.clear(); //清空vec
for (auto i : v) {
for (auto ii : i) {
if (find(this->_types.begin(), this->_types.end(), ii.first) ==
this->_types.end()) {
this->_types.push_back(ii.first);
}
}
}
};
void Park::_setupPlots(std::vector<std::map<string, int>>& v) {
for (unsigned int i = 0; i < v.size(); i++) {
for (auto ii : v[i]) {
for (int iii = 0; iii < ii.second; iii++) {
string s = m.randStr();
this->_plotsList[s] = this->_simplePlot(s, i, ii.first);
// cout << _simpleGet(_plotsList[s], "type") << endl;
}
}
}
};
const string Park::_simpleGet(const string& s, const string& what) {
std::vector<string> v;
S.split(s, v, "$$||$$");
vector<string>::iterator it = find(v.begin(), v.end(), what);
if (it != v.end()) return v[distance(v.begin(), it) + 1];
return string();
}
const string Park::_simpleUpdate(const string& s, const string& what,
const string& to) {
std::vector<string> v;
S.split(s, v, "$$||$$");
vector<string>::iterator it = find(v.begin(), v.end(), what);
if (it == v.end()) return s;
v[distance(v.begin(), it) + 1] = to;
it = find(v.begin(), v.end(), "LastOperateTime");
if (it != v.end()) v[distance(v.begin(), it) + 1] = to_string(time(NULL));
string ss = "";
for (string i : v) {
ss += i + "$$||$$";
}
return ss;
}
const string Park::_getDate() const {
char now[64];
time_t tt;
struct tm* ttime;
// tt = atol(argv[1]);
// tt = 1212132599; //uint
time(&tt);
ttime = localtime(&tt);
strftime(now, 64, "%Y-%m-%d", ttime);
string s = now;
return s;
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,31 @@
/*
* @Author: IoTcat (https://iotcat.me)
* @Date: 2019-05-24 17:01:19
* @Last Modified by: IoTcat
* @Last Modified time: 2019-05-24 17:01:19
*/
#include "plot.h"
Plot::Plot(const string& id, const unsigned int& level, const string& type) {
this->_d["id"] = id;
this->_d["level"] = to_string(level);
this->_d["type"] = type;
this->_d["car"] = "null";
this->_d["LastOperateTime"] = to_string(time(NULL));
this->_d["CreatedTime"] = to_string(time(NULL));
this->_isExist = true;
}
Plot::Plot(const string& s) {
this->_isExist = false;
if (s == "undefined") {
return;
}
this->_d = this->_d.strToData(s);
if (this->_d["id"] == "undefined") {
return;
}
this->_isExist = true;
}

@ -1,102 +1,61 @@
#ifndef __PLOT_H__
#define __PLOT_H__
#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include "../lib/ovo.h"
using namespace std;
class Plot{
public:
Plot(const string& id, const unsigned int& level, const string& type){
this->_d["id"] = id;
this->_d["level"] = to_string(level);
this->_d["type"] = type;
this->_d["car"] = "null";
this->_d["LastOperateTime"] = to_string(time(NULL));
this->_d["CreatedTime"] = to_string(time(NULL));
this->_isExist = true;
};
Plot(const string& s){
this->_isExist = false;
if(s == "undefined"){
return;
}
this->_d = this->_d.strToData(s);
if(this->_d["id"] == "undefined"){
return;
}
this->_isExist = true;
};
Plot(){
this->_isExist = false;
};
~Plot(){
};
inline isExist(){
return this->_isExist;
};
inline string getID(){
return this->_d["id"];
};
inline int getLevel(){
return atoi(this->_d["level"].c_str());
};
inline string getType(){
return this->_d["type"];
};
inline string getCar(){
return this->_d["car"];
};
inline bool isOccupied(){
return (this->_d["car"] == "null") ? false : true;
};
inline string showAll(){
return this->_d.showAll();
};
friend class Park;
//private:
ovo::data _d;
bool _isExist;
string getStrContent(){
return this->_d.dataToStr(this->_d);
};
inline void updateLevel(const unsigned int& level){
this->_d["level"] = to_string(level);
};
inline void updateType(const string& type){
this->_d["type"] = type;
};
};
#endif //__PLOT_H__
/*
* @Author: IoTcat (https://iotcat.me)
* @Date: 2019-05-24 17:01:11
* @Last Modified by: IoTcat
* @Last Modified time: 2019-05-24 17:01:11
*/
#ifndef __PLOT_H__
#define __PLOT_H__
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include "../lib/ovo.h"
using namespace std;
class Plot {
public:
Plot(const string& id, const unsigned int& level, const string& type);
Plot(const string& plot);
Plot() { this->_isExist = false; };
~Plot(){};
inline const bool isExist() const { return this->_isExist; };
inline const string getID() { return this->_d["id"]; };
inline const int getLevel() { return atoi(this->_d["level"].c_str()); };
inline const string getType() { return this->_d["type"]; };
inline const string getCar() { return this->_d["car"]; };
inline const bool isOccupied() {
return (this->_d["car"] == "null") ? false : true;
};
inline const string showAll() { return this->_d.showAll(); };
friend class Park;
private:
ovo::data _d;
bool _isExist;
inline const string getStrContent() {
return this->_d.dataToStr(this->_d);
};
inline void updateLevel(const unsigned int& level) {
this->_d["level"] = to_string(level);
};
inline void updateType(const string& type) { this->_d["type"] = type; };
};
#endif //__PLOT_H__
Loading…
Cancel
Save