-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths.py
More file actions
78 lines (68 loc) · 2.16 KB
/
s.py
File metadata and controls
78 lines (68 loc) · 2.16 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
import socket
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import os
FORMAT = "utf-8"
SIZE = 2048
FILE ="SalesFile.csv"
file = pd.read_csv(FILE)
def salesAnalysis():
try:
yr = list(sorted(set(file["Year"])))
a=list(file.groupby(['Year'])['Number'].max())
b=list(file.groupby(['Year'])['Number'].min())
x = np.arange(len(yr))
width = 0.35
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2,a, width, label='Max')
rects2 = ax.bar(x + width/2, b, width, label='Min')
ax.set_ylabel('Client Count')
ax.set_xlabel('Year')
ax.set_xticks(x)
ax.set_xticklabels(yr)
ax.set_title('Sales Analysis')
ax.legend()
fig.tight_layout()
plt.show()
op = plt.savefig("Sales.jpg")
conn.send(bytes("[Successful] Sales Log Generated ",FORMAT))
except:
conn.send(bytes("[Fail] Error",FORMAT))
def revenue():
try:
file['NetRevenue'].fillna((file["Number"] * 99), inplace=True)
file.to_csv(FILE, index=False)
conn.send(bytes(FILE,FORMAT))
except:
conn.send(bytes("[Fail] Error",FORMAT))
def addAttr(dataSet):
try:
fname = os.path.basename(dataSet)
fileNew = pd.read_csv(fname)
tempFile=pd.concat([file,fileNew], axis = 1)
tempFile.to_csv(FILE, index=False)
conn.send(bytes(FILE,FORMAT))
except:
conn.send(bytes("[Fail] Error",FORMAT))
host = socket.gethostname() #dynamic IP
port = 5001
print("[STARTING] Server is starting")
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((host,port))
server.listen()
print("[LISTENING] Server is listening")
while True:
conn, addr = server.accept() # addr = (host,port)
print("[CONNECTION] Server is connected ", addr)
inp = (conn.recv(SIZE).decode(FORMAT)).split(" ")
if inp[0] =="0":
break
elif inp[0] =="1":
salesAnalysis()
elif inp[0] =="2":
revenue()
elif inp[0] == "3":
addAttr(inp[1])
conn.close()
server.close()