Skip to content

Commit

Permalink
maintenance message and records fix
Browse files Browse the repository at this point in the history
  • Loading branch information
leftmove committed Dec 25, 2024
1 parent 70c3945 commit 27f9bf4
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 32 deletions.
21 changes: 11 additions & 10 deletions backend/routers/filer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import HTTPException, APIRouter
from fastapi import HTTPException, APIRouter, BackgroundTasks
from fastapi.responses import FileResponse, JSONResponse
from pydantic import BaseModel

Expand Down Expand Up @@ -110,8 +110,7 @@ def create_recent(cik, company, stamp):
filer_query, {"$set": {"market_value": recent_market_value}}
)

filings = database.find_filings(cik)
for stock_query, log_item in analysis.analyze_stocks(cik, filings):
for stock_query, log_item in analysis.analyze_stocks(cik, [recent_filing]):
database.edit_filer(filer_query, stock_query)
database.add_log(cik, log_item)

Expand Down Expand Up @@ -209,7 +208,7 @@ def create_filer(cik, sec_data):
tags=["filers"],
status_code=201,
)
async def query_filer(cik: str):
async def query_filer(cik: str, background: BackgroundTasks = BackgroundTasks):
filer = database.find_filer(cik)
if not filer:
try:
Expand All @@ -221,16 +220,16 @@ async def query_filer(cik: str):
if production_environment:
worker.create_filer.delay(cik, sec_data)
else:
create_filer(cik, sec_data)
background.add_task(create_filer, cik, sec_data)

res = {"description": "Filer creation started."}
else:
res = update_filer(filer)
res = update_filer(filer, background=background)

return res


def update_filer(company):
def update_filer(company, background: BackgroundTasks = BackgroundTasks):
cik = company["cik"]
time = datetime.now().timestamp()

Expand All @@ -255,13 +254,15 @@ def update_filer(company):
if production_environment:
worker.create_historical.delay(cik, company, stamp)
else:
create_historical(cik, company, stamp)
background.add_task(create_historical, cik, company, stamp)

return {"description": "Filer update started."}


@router.get("/rollback", tags=["filers"], status_code=201, include_in_schema=False)
async def rollback_filer(cik: str, password: str):
async def rollback_filer(
cik: str, password: str, background: BackgroundTasks = BackgroundTasks
):
filer = database.find_filer(cik, {"last_report": 1})
if not filer:
raise HTTPException(404, detail="CIK not found.")
Expand Down Expand Up @@ -305,7 +306,7 @@ async def rollback_filer(cik: str, password: str):
if production_environment:
worker.create_historical.delay(cik, filer, stamp)
else:
create_historical(cik, filer, stamp)
background.add_task(create_historical, cik, filer, stamp)

return {"description": "Filer rollback started."}

Expand Down
15 changes: 12 additions & 3 deletions backend/routers/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ async def trigger_error():


@router.get("/task-error", include_in_schema=False)
async def task_error():
async def task_error(password: str):

if password != os.environ["ADMIN_PASSWORD"]:
raise HTTPException(detail="Unable to give access.", status_code=403)

delay_error.delay()

return {"message": "Task error triggered."}


Expand Down Expand Up @@ -115,7 +120,9 @@ async def query_top(password: str):


@router.get("/restore", status_code=200)
async def progressive_restore(password: str):
async def progressive_restore(
password: str, background: BackgroundTasks = BackgroundTasks
):
if password != os.environ["ADMIN_PASSWORD"]:
raise HTTPException(detail="Unable to give access.", status_code=403)

Expand All @@ -125,7 +132,9 @@ async def progressive_restore(password: str):
if production_environment:
background_query("restore", all_ciks, replace_filer.delay)
else:
background_query("restore", all_ciks, replace_filer)
background_query(
"restore", all_ciks, lambda cik: background.add_task(replace_filer, cik)
)

return {"description": "Started progressive restore of filers."}

Expand Down
24 changes: 19 additions & 5 deletions backend/routers/lib/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ def analyze_timeseries(cik, local_stock, global_stock, filings):
else:
update_timeseries = False

if global_stock["ticker"] == "AAL":
pass

sold = local_stock["sold"]
first_appearance = local_stock["records"]["first_appearance"]
last_appearance = local_stock["records"]["last_appearance"]
Expand Down Expand Up @@ -434,6 +437,11 @@ def analyze_filings(cik, filings, last_report):
local_stock = filing_stocks[cusip]
cusip = local_stock["cusip"]

if local_stock["ticker"] == "AMZN":
pass
if local_stock["ticker"] == "AAL":
pass

first_appearance, last_appearance = analyze_report(
local_stock, filings_sorted
)
Expand Down Expand Up @@ -518,6 +526,11 @@ def analyze_stocks(cik, filings):
if not found_stock:
continue

if filing_stock["ticker"] == "AMZN":
pass
if filing_stock["ticker"] == "AAL":
pass

buy_stamp, sold_stamp = analyze_timeseries(
cik, filing_stock, found_stock, filings_map
)
Expand Down Expand Up @@ -606,7 +619,7 @@ def sort_pipeline(
sold: bool,
reverse: bool,
unavailable: bool,
additonal: list = [],
additional: list = [],
collection_search=database.search_filers,
):
if limit < 0:
Expand All @@ -615,8 +628,8 @@ def sort_pipeline(
pipeline = [
{"$match": {"cik": cik}},
]
if additonal:
pipeline.extend(additonal)
if additional:
pipeline.extend(additional)

pipeline.extend(
[
Expand Down Expand Up @@ -789,8 +802,9 @@ def sort_and_format(filer_ciks):
"updated": 1,
"_id": 0,
}
filers = [filer for filer in database.find_filers({"cik": {"$in": filer_ciks}}, project)]

filers = [
filer for filer in database.find_filers({"cik": {"$in": filer_ciks}}, project)
]

try:
filers_sorted = [
Expand Down
4 changes: 2 additions & 2 deletions backend/routers/lib/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

from pymongo import MongoClient

MONGO_SERVER_URL = os.environ["MONGO_SERVER_URL"]
from . import database

cwd = os.getcwd()


def save_collections():
backup_client = MongoClient(MONGO_SERVER_URL)
backup_client = MongoClient(database.MONGO_SERVER_URL)
collections = ["companies", "filers", "stocks", "statistics"]

for coll in collections:
Expand Down
4 changes: 2 additions & 2 deletions backend/routers/stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ async def query_filing(
reverse: bool,
unavailable: bool,
):
additonal = [
additional = [
{"$match": {"access_number": access_number}},
{
"$set": {
Expand All @@ -169,7 +169,7 @@ async def query_filing(
sold,
reverse,
unavailable,
additonal,
additional,
database.search_filings,
)
cursor = database.search_filings(pipeline)
Expand Down
12 changes: 6 additions & 6 deletions backend/static/statistics.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"latest": {
"count": 784,
"total": 1062224.7630047798,
"average": 1354.8785242407905
"count": 788,
"total": 1062293.1546227932,
"average": 1348.0877596735954
},
"historical": {
"count": 816,
"total": 3688239.704072237,
"average": 4519.901598127742
"count": 818,
"total": 3688874.7705163956,
"average": 4509.626858821999
}
}
Binary file modified frontend/bun.lockb
Binary file not shown.
40 changes: 39 additions & 1 deletion frontend/components/Navigation/Navigation.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
import styles from "./Navigation.module.css";
import { useState, useEffect } from "react";

import Link from "next/link";
import { font } from "@fonts";
import { font, fontLight } from "@fonts";

import Search from "components/Search/Button/Search";
import Bar from "components/Bar/Bar";

import CrossIcon from "@/public/static/cross.svg";

const Banner = () => {
const [show, setShow] = useState(null);
useEffect(() => {
if (show === null) {
setShow(localStorage.getItem("banner") === "false" ? false : true);
}
}, []);
useEffect(() => {
if (show === null) return;
localStorage.setItem("banner", show);
}, [show]);
return (
show && (
<div className={styles["banner"]}>
<div className={styles["banner-info"]}>
<span
className={[fontLight.className, styles["banner-text"]].join(" ")}
>
This website is currently undergoing maintenance to improve
reliability, performance, usability - you may experience some bugs
as a result.
</span>
</div>
<button
className={styles["banner-close"]}
onClick={() => setShow(false)}
>
<CrossIcon className={styles["banner-icon"]} />
</button>
</div>
)
);
};

const Item = ({ link, text, tab }) => (
<li className={styles["item"] + " " + font.className}>
<Link href={link} target={tab ? "_blank" : null}>
Expand All @@ -20,6 +57,7 @@ const Navigation = (props) => {
return (
<>
<Bar />
<Banner />
<nav className={styles["nav"]}>
<div className={styles["logo"]}>
<div className={styles["logo-title"]}>
Expand Down
49 changes: 49 additions & 0 deletions frontend/components/Navigation/Navigation.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,55 @@
background-color: var(--secondary);
}

.banner {
display: flex;
align-items: center;
justify-content: center;

width: 100%;
padding: 5px;

background-color: var(--primary);
}

.banner-info {
display: flex;
justify-content: center;
width: 97.75%;
}

.banner-text {
font-size: 0.9rem;
}

.banner-close {
background: none;
color: inherit;
border: none;
font: inherit;
cursor: pointer;
outline: inherit;

display: flex;
align-items: center;
justify-content: center;
justify-self: flex-end;

width: 30px;
margin-right: 5px;
}

.banner-close:hover .banner-icon {
color: white;
}

.banner-icon {
width: 100%;
height: 100%;

transition: color 0.3s ease;
}

.logo {
display: flex;
align-items: center;
Expand Down
3 changes: 2 additions & 1 deletion frontend/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const nextConfig = {
return config;
},
env: {
NEXT_PUBLIC_SERVER: "https://content.wallstreetlocal.com",
NEXT_PUBLIC_SERVER:
process.env.SERVER || "https://content.wallstreetlocal.com",
},
output: "standalone",
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@visx/shape": "^3.5.0",
"@visx/tooltip": "^3.3.0",
"axios": "^0.24.0",
"caniuse-lite": "^1.0.30001651",
"caniuse-lite": "^1.0.30001690",
"next": "13.1.6",
"next-nprogress-bar": "^2.3.5",
"next-redux-wrapper": "^8.1.0",
Expand Down
1 change: 0 additions & 1 deletion frontend/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const fontBold = Inter({ weight: "900", subsets: ["latin"] });
const fontLight = Inter({ weight: "700", subsets: ["latin"] });

function App(props) {
return <Maintenance />;
const getLayout =
props.Component.getLayout ||
(() => <Layout>{<props.Component {...props.pageProps} />}</Layout>);
Expand Down
6 changes: 6 additions & 0 deletions frontend/public/static/cross.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 27f9bf4

Please sign in to comment.