Skip to content

Commit 95f9aae

Browse files
committed
sync from mac
2 parents b381bcd + b2fa621 commit 95f9aae

5 files changed

Lines changed: 229 additions & 156 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

Files/DataTool.py

Lines changed: 189 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,189 @@
1-
# #################### Jadyn Wu ##################
2-
# Thank you for downloading Jadyn Wu's Program
3-
# I hope you find them useful in your projects
4-
# If you have any questions, find my contact in
5-
# my personal website below
6-
# Cheers!
7-
# JadynWu.com
8-
# --------------------------------------------------
9-
# Personal Website: https://jadynwu.com/
10-
# GitHub: https://github.com/YuudachiXMMY
11-
# ################################################
12-
import os, logging
13-
import numpy as np
14-
import pandas as pd
15-
import csv
16-
17-
logging.basicConfig(filename="logs.log", filemode="w", level=logging.DEBUG)
18-
19-
info = """
20-
#################### Jadyn Wu ##################
21-
Thank you for downloading Jadyn Wu's Program
22-
I hope you find them useful in your projects
23-
If you have any questions, find my contact in
24-
my personal website below
25-
Cheers!
26-
JadynWu.com
27-
--------------------------------------------------
28-
Personal Website: https://jadynwu.com/
29-
GitHub: https://github.com/YuudachiXMMY
30-
################################################
31-
"""
32-
print(info)
33-
logging.info(info)
34-
35-
directory = os.path.abspath(os.path.join(os.path.curdir))
36-
37-
print("Current Working Directory: " + directory)
38-
logging.info("Current Working Directory: " + directory)
39-
40-
#check if dir exist if not create it
41-
def check_dir(file_name):
42-
directory = os.path.dirname(file_name)
43-
if not os.path.exists(directory):
44-
os.makedirs(directory)
45-
print(directory)
46-
47-
def column_index(df, query_cols):
48-
cols = df.columns.values
49-
sidx = np.argsort(cols)
50-
return sidx[np.searchsorted(cols,query_cols,sorter=sidx)]
51-
52-
def transformToGameData():
53-
output_file = directory+'//vehicleGroupData.csv'
54-
check_dir(output_file)
55-
with open(output_file, 'w', newline='') as file:
56-
writer = csv.writer(file)
57-
58-
writer.writerow(["SN", "Movie", "Protagonist"])
59-
60-
car_color_dict = {
61-
"green" : 0,
62-
"orange" : 0,
63-
"black" : 1,
64-
"red" : 2,
65-
"blue" : 3,
66-
"white" : 4
67-
}
68-
69-
def addFunctionToData(row):
70-
res = ''
71-
if row["facial_tag"]:
72-
res += 'facerecog/'
73-
if row["glasses_tag"]:
74-
res += 'glasses/'
75-
if row["language_tag"]:
76-
res += 'language/'
77-
if row["pwd_tag"]:
78-
res += 'password/'
79-
if row["distance_tag"]:
80-
res += 'distance/'
81-
if row["male_tag"]:
82-
res += 'male/'
83-
return res.strip("/")
84-
85-
def parseData(file_name="input.xlsx"):
86-
input_df = pd.read_excel(file_name)
87-
88-
input_df["name_length"] = input_df.iloc[:,6].apply(lambda x: len(x))
89-
90-
# Cleaning for Data Analysis
91-
input_df["avg_facial"] = input_df.iloc[:,10].mean()
92-
93-
input_df["avg_glasses"] = input_df.iloc[:,11].mean()
94-
95-
input_df["avg_language"] = input_df.iloc[:,12].mean()
96-
97-
input_df["avg_pwd"] = input_df.iloc[:,14].mean()
98-
99-
input_df["avg_distance"] = input_df.iloc[:,15].mean()
100-
101-
input_df["avg_nameLength"] = input_df["name_length"].mean()
102-
103-
# Analysis DF
104-
avg_df = input_df[["avg_nameLength", "avg_facial", "avg_glasses", "avg_language", "avg_pwd", "avg_distance"]]
105-
106-
avg_df = avg_df.round(0)
107-
108-
# Cleaning for Game df
109-
input_df["facial_tag"] = input_df["avg_facial"] <= input_df.iloc[:,10]
110-
111-
input_df["glasses_tag"] = input_df["avg_glasses"] <= input_df.iloc[:,11]
112-
113-
input_df["language_tag"] = input_df["avg_language"] <= input_df.iloc[:,12]
114-
115-
input_df["pwd_tag"] = input_df["avg_pwd"] >= input_df.iloc[:,14]
116-
117-
input_df["distance_tag"] = input_df["avg_distance"] <= input_df.iloc[:,15]
118-
119-
input_df["male_tag"] = input_df.iloc[:,13].apply(lambda x: True if x>2 else False)
120-
121-
input_df['functions'] = input_df.apply(addFunctionToData, axis=1)
122-
123-
# Game df
124-
df = input_df.iloc[:, [6,7, column_index(input_df, ['functions'])[0]]]
125-
df.columns = ['name', 'vehicle', 'functions']
126-
127-
df.iloc[:,1] = df.iloc[:,1].apply(lambda x: car_color_dict[x.lower()])
128-
129-
return df, avg_df
130-
131-
try:
132-
print("Parsing the input.xlsx file...")
133-
logging.info("Parsing the input.xlsx file...")
134-
df, avg_df = parseData()
135-
print("Success!")
136-
logging.info("Success!")
137-
except Exception as e:
138-
logging.error('Error at %s', 'division', exc_info=e)
139-
140-
try:
141-
print("Saving vehicleGroupData.csv file...")
142-
logging.info("Saving vehicleGroupData.csv file...")
143-
df.to_csv('vehicleGroupData.csv', sep=',', encoding='utf-8', index=False, header=False)
144-
print("Success!")
145-
logging.info("Success!")
146-
except Exception as e:
147-
logging.error('Error at %s', 'division', exc_info=e)
148-
149-
try:
150-
print("Saving AvgAnalysis.csv file...")
151-
logging.info("Saving AvgAnalysis.csv file...")
152-
avg_df.iloc[0:1,:].to_csv('AvgAnalysis.csv', sep=',', encoding='utf-8', index=False, header=True)
153-
print("Success!")
154-
logging.info("Success!")
155-
except Exception as e:
156-
logging.error('Error at %s', 'division', exc_info=e)
1+
# #################### Jadyn Wu ##################
2+
# Thank you for downloading Jadyn Wu's Program
3+
# I hope you find them useful in your projects
4+
# If you have any questions, find my contact in
5+
# my personal website below
6+
# Cheers!
7+
# JadynWu.com
8+
# --------------------------------------------------
9+
# Personal Website: https://jadynwu.com/
10+
# GitHub: https://github.com/YuudachiXMMY
11+
# ################################################
12+
import os, logging
13+
import numpy as np
14+
import pandas as pd
15+
import csv
16+
17+
logging.basicConfig(filename="logs.log", filemode="w", level=logging.DEBUG)
18+
19+
info = """
20+
#################### Jadyn Wu ##################
21+
Thank you for downloading Jadyn Wu's Program
22+
I hope you find them useful in your projects
23+
If you have any questions, find my contact in
24+
my personal website below
25+
Cheers!
26+
JadynWu.com
27+
--------------------------------------------------
28+
Personal Website: https://jadynwu.com/
29+
GitHub: https://github.com/YuudachiXMMY
30+
################################################
31+
"""
32+
print(info)
33+
logging.info(info)
34+
35+
directory = os.path.abspath(os.path.join(os.path.curdir))
36+
37+
print("Current Working Directory: " + directory)
38+
logging.info("Current Working Directory: " + directory)
39+
40+
#check if dir exist if not create it
41+
def check_dir(file_name):
42+
directory = os.path.dirname(file_name)
43+
if not os.path.exists(directory):
44+
os.makedirs(directory)
45+
print(directory)
46+
47+
def column_index(df, query_cols):
48+
cols = df.columns.values
49+
sidx = np.argsort(cols)
50+
return sidx[np.searchsorted(cols,query_cols,sorter=sidx)]
51+
52+
def transformToGameData():
53+
output_file = directory+'//vehicleGroupData.csv'
54+
check_dir(output_file)
55+
with open(output_file, 'w', newline='') as file:
56+
writer = csv.writer(file)
57+
58+
writer.writerow(["SN", "Movie", "Protagonist"])
59+
60+
car_color_dict = {
61+
"green" : 0,
62+
"orange" : 0,
63+
"black" : 1,
64+
"red" : 2,
65+
"blue" : 3,
66+
"white" : 4
67+
}
68+
69+
def addFunctionToData(row):
70+
res = ''
71+
if row["facial_tag"]:
72+
res += 'facerecog/'
73+
if row["glasses_tag"]:
74+
res += 'glasses/'
75+
if row["language_tag"]:
76+
res += 'language/'
77+
if row["pwd_tag"]:
78+
res += 'password/'
79+
if row["distance_tag"]:
80+
res += 'distance/'
81+
if row["male_tag"]:
82+
res += 'male/'
83+
return res.strip("/")
84+
85+
def parseData(file_name="input.csv"):
86+
try:
87+
print("Trying to Read file: " + file_name)
88+
if file_name.endswith('.csv'):
89+
input_df = pd.read_csv(file_name)
90+
else:
91+
input_df = pd.read_excel(file_name)
92+
print("Success!")
93+
logging.info("Success!")
94+
except:
95+
print("Cannot Read file: " + file_name)
96+
logging.info("Cannot Read file: " + file_name)
97+
98+
try:
99+
print("Try reading input.csv")
100+
logging.info("Try reading input.csv")
101+
input_df = pd.read_csv("input.csv")
102+
print("Success!")
103+
logging.info("Success!")
104+
except Exception as e:
105+
logging.error('Error at %s', 'division', exc_info=e)
106+
107+
108+
print("Parsing the file...")
109+
logging.info("Parsing the file...")
110+
111+
input_df["name_length"] = input_df.iloc[:,6].apply(lambda x: len(x))
112+
113+
# Cleaning for Data Analysis
114+
input_df["avg_facial"] = input_df.iloc[:,10].mean()
115+
116+
input_df["avg_glasses"] = input_df.iloc[:,11].mean()
117+
118+
input_df["avg_language"] = input_df.iloc[:,12].mean()
119+
120+
input_df["avg_pwd"] = input_df.iloc[:,14].mean()
121+
122+
input_df["avg_distance"] = input_df.iloc[:,15].mean()
123+
124+
input_df["avg_nameLength"] = input_df["name_length"].mean()
125+
126+
# Analysis DF
127+
avg_df = input_df[["avg_nameLength", "avg_facial", "avg_glasses", "avg_language", "avg_pwd", "avg_distance"]]
128+
129+
avg_df = avg_df.round(0)
130+
131+
# Cleaning for Game df
132+
input_df["facial_tag"] = input_df["avg_facial"] <= input_df.iloc[:,10]
133+
134+
input_df["glasses_tag"] = input_df["avg_glasses"] <= input_df.iloc[:,11]
135+
136+
input_df["language_tag"] = input_df["avg_language"] <= input_df.iloc[:,12]
137+
138+
input_df["pwd_tag"] = input_df["avg_pwd"] >= input_df.iloc[:,14]
139+
140+
input_df["distance_tag"] = input_df["avg_distance"] <= input_df.iloc[:,15]
141+
142+
input_df["male_tag"] = input_df.iloc[:,13].apply(lambda x: True if x>2 else False)
143+
144+
input_df['functions'] = input_df.apply(addFunctionToData, axis=1)
145+
146+
# Game df
147+
df = input_df.iloc[:, [6,7, column_index(input_df, ['functions'])[0]]]
148+
df.columns = ['name', 'vehicle', 'functions']
149+
150+
df.iloc[:,1] = df.iloc[:,1].apply(lambda x: car_color_dict[x.lower()])
151+
152+
return df, avg_df
153+
154+
def readInput():
155+
res = input("""
156+
Please enter your file name
157+
press enter directly to read input.csv
158+
(e.g. input.csv , Class1.xlsx)
159+
""")
160+
if res == "":
161+
res = "input.csv"
162+
return res
163+
164+
try:
165+
res = readInput()
166+
df, avg_df = parseData(res)
167+
print("Success!")
168+
logging.info("Success!")
169+
170+
try:
171+
print("Saving vehicleGroupData.csv file...")
172+
logging.info("Saving vehicleGroupData.csv file...")
173+
df.to_csv('vehicleGroupData.csv', sep=',', encoding='utf-8', index=False, header=False)
174+
print("Success!")
175+
logging.info("Success!")
176+
except Exception as e:
177+
logging.error('Error at %s', 'division', exc_info=e)
178+
179+
try:
180+
print("Saving AvgAnalysis.csv file...")
181+
logging.info("Saving AvgAnalysis.csv file...")
182+
avg_df.iloc[0:1,:].to_csv('AvgAnalysis.csv', sep=',', encoding='utf-8', index=False, header=True)
183+
print("Success!")
184+
logging.info("Success!")
185+
except Exception as e:
186+
logging.error('Error at %s', 'division', exc_info=e)
187+
188+
except Exception as e:
189+
logging.error('Error at %s', 'division', exc_info=e)

Files/dist/DataTool-v1.exe

87.7 MB
Binary file not shown.

Files/dist/READ_ME.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#################### Jadyn Wu ##################
2+
Thank you for downloading Jadyn Wu's Program
3+
I hope you find them useful in your projects
4+
If you have any questions, find my contact in
5+
my personal website below
6+
Cheers!
7+
JadynWu.com
8+
--------------------------------------------------
9+
Personal Website: https://jadynwu.com/
10+
GitHub: https://github.com/YuudachiXMMY
11+
################################################
12+
13+
################# Program Specification ##############
14+
Input file:
15+
- input.csv
16+
17+
output files:
18+
- vehicleGroupData.csv : used for game program
19+
- AvgAnalysis.csv : analysis the average information of some data
20+
21+
22+
Before RUNNING, please ensrue that:
23+
1. The input file is renamed to input.csv
24+
2. DataTool.exe and input.csv are in the SAME folder/directory
25+
26+
27+
To RUN:
28+
1. Double-Click the DataTool.exe
29+
30+
31+
Data format of input.csv:
32+
- Names must be in column G
33+
- Colors must be in column H
34+
- Number of Team Members must be in column I
35+
- Facial Recognition must be in column K
36+
- Glassess must be in column L
37+
- Languages must be in column M
38+
- Number of People identifying themselve as Male must be in column N
39+
- Password must be in column O
40+
- Distance must be in column P

0 commit comments

Comments
 (0)