commit 951f8f6c154aa11f34cea4e2b8c026f49dd8f413 Author: TinyAtoms Date: Tue May 28 13:46:55 2019 -0300 quick sketch of components diff --git a/src/Customer.cpp b/src/Customer.cpp new file mode 100644 index 0000000..9b5f2a8 --- /dev/null +++ b/src/Customer.cpp @@ -0,0 +1,30 @@ +#include "headers/Customer.h" +#include + +Customer::Customer(int id_, string name_, string card_code_) + : id { id_ } + , name { name_ } + , card_code { card_code_ } +{ +} + +void Customer::clock_in( int s_id) +{ + Park_time pt{id, s_id}; + park_instances.push_back(pt); +} +void Customer::clock_out(int s_id){ + park_instances[park_instances.size()-1].clock_out(id, s_id); +} + + + +void Customer::gen_monthly(){ + std::cout << "NAME: " << name << " card code: " << card_code << "\n"; + std::cout << "-------------------------------------------------\n"; + for (auto& i : park_instances) { + // need some logic to only include from this month + std::cout << i; + } + std::cout << "-------------------------------------------------\n\n"; +} \ No newline at end of file diff --git a/src/Park_spot.cpp b/src/Park_spot.cpp new file mode 100644 index 0000000..95d1928 --- /dev/null +++ b/src/Park_spot.cpp @@ -0,0 +1,20 @@ +#include "headers/Park_spot.h" + +Park_spot::Park_spot(int id_){ + parked = nullptr; + id = id_; + taken = false; +} + +void Park_spot::clock(Customer* c_customer){ + if (!taken){ + parked = c_customer; + taken = true; + parked->clock_in(id); + } + else{ + taken = false; + parked->clock_out(id); + parked = nullptr; + } +} \ No newline at end of file diff --git a/src/Park_time.cpp b/src/Park_time.cpp new file mode 100644 index 0000000..267e0c0 --- /dev/null +++ b/src/Park_time.cpp @@ -0,0 +1,45 @@ +#include"headers/Park_time.h" +#include +#include + + +Park_time::Park_time(int c_id, int s_id) + : customer_id { c_id } + , spot_id { s_id } + , duration { 0 } + , start { high_resolution_clock::now() } +{ +} + +void Park_time::clock_out(int c_id, int s_id) +{ + + if (c_id != customer_id) { + std::cout << "wrong customer id, you are at the wrong location"; + return; + } + if (s_id != spot_id) { + std::cout << "Wrong spot id, you're at the wrong location"; + return; + } + + if (!duration) { + end = high_resolution_clock::now(); + duration = duration_cast(end - start).count(); // use mins later + + } else { + std::cout << "Already clocked out. Something is wrong \n"; + } +} + + +std::ostream& operator<<(std::ostream& os, const Park_time & pt){ + std::time_t start_ = system_clock::to_time_t(pt.start); + std::time_t end_ = system_clock::to_time_t(pt.end); + os << "- - - - - - - - - - - - - - - - - - - -\n"; + os << "Clocked in :" << std::ctime(&start_); + os << "clocked out : " << std::ctime(&end_); + os << "duration : " << pt.duration << "\n"; + os << "- - - - - - - - - - - - - - - - - - - -\n"; + return os; +} \ No newline at end of file diff --git a/src/headers/Customer.h b/src/headers/Customer.h new file mode 100644 index 0000000..58589e0 --- /dev/null +++ b/src/headers/Customer.h @@ -0,0 +1,37 @@ +#ifndef CUSTOMER_H +#define CUSTOMER_H +#pragma once + +#include +#include +#include "Park_time.h" + +using std::vector; +using std::string; + +/* +db repr of Customer +int id (not null, auto increment) +string name (not nulll) +string card_code (not null) + +*/ + +class Customer { +public: + int id; + string name; + string card_code; + void clock_in(int s_id); + void clock_out(int s_id); + // void gen_weekly(); + void gen_monthly(); + Customer(int id_, string name_, string card_code_); + +private: + vector park_instances; +}; + + + +#endif // CUSTOMER_H \ No newline at end of file diff --git a/src/headers/Park_spot.h b/src/headers/Park_spot.h new file mode 100644 index 0000000..e3984cf --- /dev/null +++ b/src/headers/Park_spot.h @@ -0,0 +1,21 @@ +#include "Customer.h" + + +/* +db representation: +int id not null +bool taken not null +int customer_id (null) (many to one, foreign key, whatever) +*/ + +class Park_spot { + public: + int id; + bool taken; + Customer* parked; + Park_spot(int id_); + void clock(Customer* c_customer); + private: +}; + + diff --git a/src/headers/Park_time.h b/src/headers/Park_time.h new file mode 100644 index 0000000..5778d31 --- /dev/null +++ b/src/headers/Park_time.h @@ -0,0 +1,39 @@ +#ifndef PARK_TIME_H +#define PARK_TIME_H +#pragma once + +#include +#include + + +using namespace std::chrono; + +/* +db repr of Park_time +int id (not null, auto increment) +int customer_id (not null) (many to one or something like that) +int spot_id (not null, many to one or something like that) +int duration +datetime start (not null) +datetime end +*/ + +class Park_time { +public: + int id; + int customer_id; + int spot_id; + int duration; + Park_time(int c_id, int s_id); + void clock_out(int c_id, int s_id); + friend std::ostream& operator<<(std::ostream& os, const Park_time & pt); + +private: + high_resolution_clock::time_point start; + high_resolution_clock::time_point end; +}; + + + + +#endif // Park_time \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..dc08007 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,55 @@ +#include "headers/Park_spot.h" +#include +#include // to make pausing work, not sure if i need chrono, or this, or both +#include + +void Wait(int sec) +{ + std::this_thread::sleep_for(seconds { sec }); +} + +using std::cout; + +int main() +{ + std::vector spots { + 1, 2, 3, 4, 5 + }; + std::vector customers { + { 1, "Sagar Ram", "eddgh" }, + { 2, "Shaq", "wsdfwefgv" }, + { 3, "Josh", "WDFGWEF" }, + { 4, "Stefano", "EDGGERG" } + }; + + spots[1].clock(&customers[3]); // stefano parks at spot 2 + Wait(2); + spots[3].clock(&customers[2]); // josh parks at spot 4 + Wait(1); + spots[1].clock(&customers[3]); // stefano clocks out of spot 1 + Wait(5); + spots[1].clock(&customers[1]); // shaq clocks in at spot 1 + Wait(6); + spots[2].clock(&customers[0]); // sagar clocks in at spot 3. what the fuck is he doing here? + Wait(2); + spots[2].clock(&customers[0]); // sagar clocks out from spot 2 + Wait(3); + spots[3].clock(&customers[2]); // josh clocks out from spot 4 + spots[1].clock(&customers[1]); // shaq clocks out at spot 1 + + spots[2].clock(&customers[1]); // shaq clocks out at spot 3 + Wait(4); + spots[2].clock(&customers[1]); // shaq clocks out at spot 2 + + /* + so: + stefan parked for 3 secs + josh parked for 17 secs + shaq parked 2 times, once for 4 and another for 11 secs + sagar parked for 2 secs + */ + customers[0].gen_monthly(); + customers[1].gen_monthly(); + customers[2].gen_monthly(); + customers[3].gen_monthly(); +} \ No newline at end of file