-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisits.py
59 lines (47 loc) · 1.82 KB
/
Visits.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from datetime import datetime
from geopy import distance
from google_calendar import create_link
class Visits:
def __init__(self, country, point, radius):
self.city = None
self.postcode = None
self.country_name = None
self.initial_date = None
self.final_date = None
self.initial_point = point
self.records = 1
self.country = country
self.radius = radius
self.visit_link = ""
def __str__(self):
return f"\n---\n" \
f"Country: {self.country_name}\n" \
f"City: {self.city}\n" \
f"Arrival: {datetime.fromtimestamp(self.initial_date)}({self.initial_date})\n" \
f"Departure: {datetime.fromtimestamp(self.final_date)}({self.final_date})\n" \
f"Google Calendar Link: {self.visit_link}" \
f"---"
def start_count(self, timestamp):
self.initial_date = timestamp
def stop_count(self, timestamp):
self.final_date = timestamp
self.visit_link = create_link(self)
def add_records(self, xtimes):
self.records = xtimes
def get_total_visit_time(self):
return self.final_date - self.initial_date
def big_change(self, new_point):
if distance.great_circle(self.initial_point[:2], new_point[:2]).km < self.radius:
return False
return True
def add_details(self, country_name, city, postcode):
self.city = city
self.postcode = postcode
self.country_name = country_name
def new_visit(timestamp, new_country, point, radius):
new_visit_object = Visits(new_country, point, radius)
new_visit_object.start_count(timestamp)
return new_visit_object
def close_visit(visit, xrecords, final_timestamp):
visit.stop_count(final_timestamp)
visit.add_records(xrecords)