added required field to manufacturers

This commit is contained in:
Brandon Egger 2023-03-29 00:05:42 -05:00
parent 088f7c3540
commit 54eff320bf
3 changed files with 26 additions and 7 deletions

View File

@ -53,12 +53,17 @@ type PlatformLink {
link String
}
type Manufacturer {
name String
required Boolean
}
model AuditoryResource {
id String @id @default(auto()) @map("_id") @db.ObjectId
icon String
name String
description String
manufacturer String
manufacturer Manufacturer?
ages RangeInput
skills Skill[]
skill_levels SkillLevel[]

View File

@ -2,8 +2,9 @@ import typer
import pymongo
import pandas as pd
import numpy as np
import math
MONGO_URL = "mongodb://localhost:27017/atr_db?replicaSet=test"
MONGO_URL = "mongodb://localhost:27017/"
MONGO_DB = "dev"
def upload_to_mongo(resources, ar_col):
@ -20,6 +21,19 @@ def get_entry(row, col, default_val=np.nan):
return default_val
return row.loc[col]['entry']
def get_manufacturer(row, col):
'''
Get entry column for a manufacturer.
'''
if row.loc[col]['entry'] is np.nan:
return None
required = row.loc[col]['required']
return {
"name": row.loc[col]['entry'],
"required": isinstance(required, str)
}
def get_selected_options(row, col):
return row.loc[col].dropna(inplace=False).index.to_list()
@ -35,7 +49,7 @@ def get_platform_links(row):
def main(path: str):
df = pd.read_excel(path, header=[0,1])
mongo_client = pymongo.MongoClient(MONGO_URL)
mongo_db = mongo_client[MONGO_DB]
ar_col = mongo_db["AuditoryResource"]
@ -48,7 +62,7 @@ def main(path: str):
resource["name"] = get_entry(df.iloc[i], 'Resource:', "n/a")
resource["icon"] = get_entry(df.iloc[i], 'Icon:', "")
resource["description"] = get_entry(df.iloc[i], 'Description:', "n/a")
resource["manufacturer"] = get_entry(df.iloc[i], 'Manufacturer:', "")
resource["manufacturer"] = get_manufacturer(df.iloc[i], 'Manufacturer:')
resource["platform_links"] = get_platform_links(df.iloc[i])
resource["ages"] = get_range(df.iloc[i], 'Age Group:')
resource["skills"] = get_selected_options(df.iloc[i], 'Skills:')
@ -57,7 +71,7 @@ def main(path: str):
print(f"Finished parsing resource on line {i+2}:")
print(resource)
print(f"--------------------------------\n")
print("--------------------------------\n")
resources.append(resource)
@ -66,4 +80,4 @@ def main(path: str):
print("Upload success!")
if __name__ == "__main__":
typer.run(main)
typer.run(main)

View File

@ -68,7 +68,7 @@ export const ResourceInfo = ({resource, showMoreInfo}: {resource: AuditoryResour
</div>
<div className="grid place-items-center">
<div className="">
<h2 className="text-xs italic text-gray-600">{resource.manufacturer}</h2>
<h2 className="text-xs italic text-gray-600">{resource.manufacturer?.name}</h2>
<h1 className="font-bold text-xl">{resource.name}</h1>
<PlatformInfo platformLinks={resource.platform_links}/>
<PriceIcons type={resource?.payment_options[0] ?? 'FREE'} />