Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint": "eslint \"./**/*.js*\"",
"lint:fix": "eslint --fix \"./**/*.js*\"",
"test": "vitest",
"check-env": "node ./utils/checkEnv"
"check-env": "node ./src/utils/checkEnv"
},
"husky": {
"hooks": {
Expand Down
41 changes: 28 additions & 13 deletions src/scripts/updateHfDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
from tqdm import tqdm
from huggingface_hub import HfApi, login
from dotenv import load_dotenv
from datetime import datetime
load_dotenv()

def get_current_year():
return str(datetime.now().year)

# set environment as 'dev' or 'prod'
ENV = os.getenv('VITE_ENV')

Expand All @@ -21,26 +25,35 @@

def dlData():
'''
Download the current year's dataset from data.lacity.org
Download the current year's dataset from data.lacity.org.
Returns the year, so it can be passed to subsequent steps.
'''
year = get_current_year()
url = "https://data.lacity.org/api/views/h73f-gn57/rows.csv?accessType=DOWNLOAD"
outfile = "2025.csv"
outfile = f"{year}.csv"

response = requests.get(url, stream=True)

# If we get a 4xx or 5xx HTTP status, raise an exception and stop processing altogether
response.raise_for_status()

# Save downloaded file
with open(outfile, "wb") as file:
for data in tqdm(response.iter_content()):
file.write(data)

return year


def hfClean():
def hfClean(year=None):
'''
Clean the dataset by removing problematic string combinations and update timestamp to ISO format
'''
infile = "2025.csv"
fixed_filename = "2025-fixed.csv"
clean_filename = "2025-clean.parquet"
if year is None:
year = get_current_year()
infile = f"{year}.csv"
fixed_filename = f"{year}-fixed.csv"
clean_filename = f"{year}-clean.parquet"

# List of problmenatic strings to be replaced with ""
replace_strings = ["VE, 0"]
Expand All @@ -65,13 +78,15 @@ def hfClean():
print(f"File {infile} not found.")


def hfUpload():
def hfUpload(year=None):
'''
Upload the clean dataset to huggingface.co
'''
local_filename = '2025-clean.parquet'
dest_filename = '2025.parquet'
repo_name = '2025'
if year is None:
year = get_current_year()
local_filename = f'{year}-clean.parquet'
dest_filename = f'{year}.parquet'
repo_name = f'{year}'
repo_type = 'dataset'

repo_id = f"{HF_USERNAME}/{repo_name}"
Expand All @@ -95,9 +110,9 @@ def cleanUp():


def main():
dlData()
hfClean()
hfUpload()
year = dlData()
hfClean(year)
hfUpload(year)
cleanUp()


Expand Down
4 changes: 2 additions & 2 deletions src/utils/checkEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const red = '\x1b[31m%s\x1b[0m';
const green = '\x1b[32m%s\x1b[0m';
const vitePrefix = 'VITE_';

const envPath = path.resolve(__dirname, '../.env');
const exampleEnvPath = path.resolve(__dirname, '../.example.env');
const envPath = path.resolve(__dirname, '../../.env');
const exampleEnvPath = path.resolve(__dirname, '../../.example.env');

function getEnv(fileName) {
return dotenv.parse(fs.readFileSync(fileName));
Expand Down
6 changes: 5 additions & 1 deletion src/utils/test-utils.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react'
import { render } from '@testing-library/react'
import { Provider } from 'react-redux'
import { ThemeProvider } from '@mui/material/styles'
import { setupStore } from '../redux/store'
import theme from '@theme/theme'

// https://redux.js.org/usage/writing-tests#setting-up-a-reusable-test-render-function
export function renderWithProviders(ui, extendedRenderOptions = {}) {
Expand All @@ -13,7 +15,9 @@ export function renderWithProviders(ui, extendedRenderOptions = {}) {
} = extendedRenderOptions

const Wrapper = ({ children }) => (
<Provider store={store}>{children}</Provider>
<Provider store={store}>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</Provider>
)

// Return an object with the store and all of RTL's query functions
Expand Down
2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default defineConfig(() => {
},
test: {
environment: 'jsdom',
setupFiles: 'utils/test-setup.js'
setupFiles: 'src/utils/test-setup.js'
}
};
});