-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
156 lines (116 loc) · 3.92 KB
/
main.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
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
## Imports
import MAL_my_data
import kaggle_dataset
import model
import os
import numpy as np
import pandas as pd
DEBUG = 0
CACHE = 0
# numeric_keys = {
# 'genres': {},
# 'producers': {},
# 'licensors': {},
# 'studios': {}
# }
# def To_Int(str, list):
# # Convert strings to integer keys
# dict = numeric_keys[str]
# new_list = []
# for item in list:
# if item not in dict:
# dict[item] = len(dict) + 1
# new_list.append(dict[item])
# numeric_keys[str] = dict
# return new_list
def get_cached_data():
ani_list = pd.read_csv('./cache/ani_list.csv')
rating_list = pd.read_csv('./cache/user_list.csv', usecols=["user_id", "anime_id", "rating"])
# User should rate atleast 400 animies
n_ratings = rating_list['user_id'].value_counts()
rating_list = rating_list[rating_list['user_id'].isin(n_ratings[n_ratings >= 400].index)].copy()
return ani_list, rating_list
def get_anime_data():
## Download and return dataframe with MAL anime database
# genres = {'Action': 1,
# 'Adventure': 2,
# 'Avant Garde': 3,
# 'Award Winning': 4,
# 'Boys Love': 5,
# 'Comedy': 6,
# 'Drama': 7,
# 'Fantasy': 8,
# 'Girls Love': 9,
# 'Gourmet': 10,
# 'Horror': 11,
# 'Mystery': 12,
# 'Romance': 13,
# 'Sci-Fi': 14,
# 'Slice of Life': 15,
# 'Sports': 16,
# 'Supernatural': 17,
# 'Suspense': 18,
# 'Ecchi': 19,
# 'Erotica': 20,
# 'Hentai': 21}
kaggle_dataset.load_set()
ani_list = pd.read_csv('./data/anime-dataset-2023.csv')
rating_list = pd.read_csv('./data/users-score-2023.csv', usecols=["user_id", "anime_id", "rating"])
# User should rate atleast 400 animes
n_ratings = rating_list['user_id'].value_counts()
rating_list = rating_list[rating_list['user_id'].isin(n_ratings[n_ratings >= 400].index)].copy()
return ani_list, rating_list
def delete_data():
if os.path.exists('data'):
os.remove('data')
return
def select_input(select):
if DEBUG:
print("select_input")
match select:
case 0:
print("Shuting down...")
case 1:
if DEBUG:
print("case 1")
if CACHE:
ani_list, rating_list = get_cached_data() # Dataframe
my_list = pd.read_csv('./cache/my_list.csv')
else:
ani_list, rating_list = get_anime_data() # Dataframe
# TODO: Implement Timeout
my_list = MAL_my_data.get_my_anime_list() # Dataframe
ani_list.to_csv('./cache/ani_list.csv')
rating_list.to_csv('./cache/user_list.csv')
my_list.to_csv('./cache/my_list.csv') # Cache my data
# TODO: return files
model.rec_anime(ani_list, my_list, rating_list)
case 2: #TODO
print("Feature not implemented \nChoose again")
# manga_list = get_manga_data()
# my_list = MAL_my_data.get_my_manga_list()
# rec_manga(manga_list, my_list)
case 3:
delete_data()
get_anime_data()
case _:
print("Invalid Selection\n")
def list_menu():
if DEBUG:
print("list_menu")
print("\n1: Recommend Anime" +
"\n2: Recommend Manga *WIP Placeholder*" + #TODO
"\n3: Reset Data" +
"\n0: Exit")
return int(input("\nEnter Selection: "))
def main():
# Authorize MAL API
MAL_my_data.OAuth2()
# manga_list = get_manga_data()
select = -1 # Some Arbitrary number
while select != 0:
select = list_menu()
select_input(select)
# Exit program
exit()
main()