forked from aparoski/WhiteoutSurvivalBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData.py
125 lines (80 loc) · 4.36 KB
/
Data.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import pandas as pd
import numpy as np
from datetime import datetime, timedelta, date
#move this into Window_Finder when ready
#from Window_Finder import Bluestack_window_return
import os
#temp stopgap
import win32gui as w
class Window_Dataframe:
def __init__(self):
"""check to see if the dataframe exists. if not, create it and save.
if yes, load it. when the dataframe is loaded any times in
the past will be removed"""
self.path = os.path.dirname(__file__) + "\\Whiteout_Schedule.csv"
if os.path.isfile(self.path):
#load dataframe
Window_Stats = pd.read_csv(self.path)
#remove times from the past
Window_Stats = Window_Stats[(Window_Stats["completion_date"].apply(lambda x: datetime.strptime(x, "%Y-%m-%d %H:%M:%S")) >= datetime.utcnow())
|
(Window_Stats["event_length"] != "s")]
else:
def current_windows():
def enumHandler(hwnd, list):
if ("BlueStacks App Player" in w.GetWindowText(hwnd)):
list.append([hwnd, w.GetWindowText(hwnd), w.GetWindowRect(hwnd), 0])
window_list = []
w.EnumWindows(enumHandler, window_list)
return(window_list)
windows = current_windows()
col_len = np.arange(len(windows))
Window_Stats = pd.DataFrame({"Window_Name" : [i[1] for i in windows],
"window_hwnd" : [i[0] for i in windows],
"Activity" : col_len,
"completion_date" : col_len,
"event_length" : col_len})
#force future time for the first few entries so they are never removed
Window_Stats["completion_date"] = datetime(9999, 1, 1, 1, 1, 1)
Window_Stats["completion_date"] = Window_Stats["completion_date"].values.astype('datetime64[s]')
Window_Stats["Activity"] = Window_Stats["Activity"].astype('category')
Window_Stats["event_length"] = Window_Stats["event_length"].astype('category')
self.df = Window_Stats
def save(self) -> None:
self.df.to_csv(self.path, index = False)
def add(self, window_name, hwnd, activity_name, time, length) -> None:
"""take the amount of time to run an activity
and marks a time in the future for it's completion.
times marked are in UTC
directly modifies the dataframe"""
if length not in ["s", "l"]:
raise("value error: select 's' for short event or 'l' for long event")
future_time = datetime.utcnow() + timedelta(0, time)
new_record = pd.DataFrame({"Window_Name" : window_name,
"window_hwnd" : hwnd,
"Activity" : activity_name,
"completion_date" : future_time,
"event_length" : length}, index = [0])
new_record["completion_date"] = new_record["completion_date"].values.astype('datetime64[s]')
self.df = pd.concat([self.df, new_record], axis = 0).reset_index(drop = True)
def latest_event(self, current = True):
latest_event = self.df[self.df["completion_date"].apply(lambda x: x.year < 3999)].sort_values("completion_date", ascending = True).head(1)
if current:
latest_event = latest_event[datetime.utcnow() >= latest_event["completion_date"]]
return(latest_event)
#function to drop record from df.
#check to see if latest event index is related to df
if __name__ == '__main__':
print(os.path.dirname(__file__))
schedule = Window_Dataframe()
# schedule.add("test", 1234, "apples", 0, "l")
schedule.add("test", 1234, "apples", 100, "s")
# schedule.add("test", 1234, "apples", 600, "s")
# schedule.add("test", 1234, "apples", 800, "s")
latest_event = schedule.latest_event()
print(datetime.utcnow())
print(latest_event["completion_date"].shape)
print(latest_event)
print(schedule.df.sort_values(["completion_date"], ascending = False))
#print(datetime.utcnow() >= latest_event["completion_date"].iloc[0])
# schedule.save()