-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataframe.py
More file actions
160 lines (133 loc) · 4.33 KB
/
dataframe.py
File metadata and controls
160 lines (133 loc) · 4.33 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"""
File:
dataframe.py
Description:
Declaration of dataset used in GolgiBot
Author:
Pedro Croso <pedrocroso@usp.br>
"""
import pandas as pd
from config import *
from tkinter import messagebox
class GolgiDataFrame():
"""Class for the DataSet
"""
columns = ['id', 'nome', 'dosagem', 'apresentacao', 'position']
def __init__(self) -> None:
self.df = pd.read_csv("dados/drug_data.csv")
self.df = self.df.set_index('id')
def add_item(self, item):
"""
Description:
Add a new item to drugs data frame
Params:
item: list of dictionaries
{
"id": "TheID",
"nome": "TheName",
"dosagem": "TheDose",
"apresentacao": "TheProducer",
"position": "ThePosition"
}
"""
new_item = pd.DataFrame(item)
new_item = new_item.set_index('id')
self.df = pd.concat([self.df, new_item])
def delete_item(self, key):
"""
Description: delete item with desired key
Params:
key(int): id of item to be removed
"""
print("teste")
try:
self.df = self.df.drop(key)
except:
self.df = self.df.drop(int(float(key)))
#raise print(f"Item number {key} not found")
def modify_item(self, key, item):
"""
Description: Modify a drug item from the dataset
Params:
key(int): key for the item id
item(dictionary):
{
"id": "TheID",
"nome": "TheName",
"dosagem": "TheDose",
"apresentacao": "TheProducer",
"position": "ThePosition"
}
"""
self.delete_item(key)
#self.df = self.df.drop(key)
new_item = pd.DataFrame(item)
new_item = new_item.set_index('id')
self.df = pd.concat([self.df, new_item], axis=0)
#self.df = self.df.merge(new_item, on='id')
def update_amount(self, id, amount):
"""
Description: Update the drug stock amount from the dataset
Params:
id(int): key for the item id
amount(int): amount to be subtracted from the current stock
"""
initial_amount = self.df.at[id, 'estoque']
final_amount = int(initial_amount) - amount
self.df.at[id, 'estoque']=f'{final_amount}'
self.save_to_disk()
import pandas as pd
def get_items(self, id="0", nome="", dosagem="", apresentacao=""):
"""
Description: Search the dataframe to look for matches
Params:
id = ""
nome = ""
dosagem = ""
apresentacao = ""
Return: A pandas dataset with match items
"""
df_search = self.df
df_search = df_search.reset_index()
print(self.df)
try:
id = int(float(id))
except:
if (id == ""):
pass
else:
print("Invalid ID")
if (id == ""):
id = -1
if (nome == ""):
nome = "NO NOME"
if (dosagem == ""):
dosagem = "NO DOSE"
if (apresentacao == ""):
apresentacao = "NO APRES"
print("Search parameter:")
print("Nome:", nome)
print("ID:", id)
print("Dosagem:", dosagem)
print("Apresentacao:", apresentacao)
# Full Match
selected_items = df_search[(df_search['nome'].str.contains(nome, case=False)) | (df_search['id'] == id) | (df_search['dosagem'].str.contains(dosagem, case=False)) | (df_search['apresentacao'].str.contains(apresentacao, case=False))]
print("Full match")
print(selected_items)
return selected_items
def save_to_disk(self):
"""
Description: saves the dataset to a .csv file
"""
self.df.to_csv('dados/drug_data.csv')#, index=False)
golgi_data = GolgiDataFrame()
'''item = {
"id": ["00000"],
"nome": ["TheName"],
"dosagem": ["TheDose"],
"apresentacao": ["TheProducer"],
"position": ["ThePosition"]
}
df = pd.DataFrame(item)
df.set_index('id')
df.to_csv('Golgi_v0.1\dados\drug_data.csv', index=False)'''