-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplan.py
71 lines (57 loc) · 2.47 KB
/
plan.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pandas as pd
import json
class Plan:
def __init__(self):
self.columns = ["PlanID", "DocumentID", "Purpose", "Perspectives", "ResultID", "Status"]
self.data = pd.DataFrame(columns=self.columns)
self.current_id = 1
def set_strategy(self, detailed_strategy: str):
self.detailed_strategy = detailed_strategy
def add_data(self, document_id, purpose, perspectives):
data = [[self.current_id, document_id, purpose, perspectives, "", "None"]]
new_data = pd.DataFrame(data, columns=self.columns)
self.data = pd.concat([self.data, new_data], ignore_index=True)
self.current_id += 1
def update_status_doing(self, plan_id: int):
self.data.loc[self.data["PlanID"] == plan_id, "Status"] = "Doing"
def update_status_done(self, plan_id: int, memory_id: int):
self.data.loc[self.data["PlanID"] == plan_id, "Status"] = "Done"
self.data.loc[self.data["PlanID"] == plan_id, "ResultID"] = memory_id
def save_to_json(self, file_path):
json_data = dict()
json_data["DetailedStrategy"] = self.detailed_strategy
json_data["Plan"] = self.data.to_dict(orient="records")
with open(file_path, "w", encoding="utf-8") as f:
json.dump(json_data, f, indent=4, ensure_ascii=False)
def get_json_data(self):
self.json_data = dict()
self.json_data["DetailedStrategy"] = self.detailed_strategy
self.json_data["Plan"] = self.data.to_dict(orient="records")
return self.json_data
def load_from_json(self, file_path):
with open(file_path, 'r') as file:
self.json_data = json.load(file)
self.detailed_strategy = self.json_data["DetailedStrategy"]
self.data = pd.DataFrame(self.json_data['Plan'])
def get_data(self):
return self.data
def get_data_by_id(self, plan_id=None):
if plan_id is None:
plan_id = self.current_id - 1
return self.data.loc[self.data["PlanID"] == plan_id]
if __name__ == "__main__":
plan = Plan()
i = 0
count = 2
while i < count:
doc_id = input("DocumentID> ")
purpose = input("Purpose> ")
perspectives = input("Perspectives> ")
ids = input("ResultID> ")
status = input("Status> ")
plan.add_data(doc_id, purpose, perspectives, ids, status)
print(plan.get_data_by_id())
i += 1
plan.save_to_json("test/result/plan.json")