Skip to content

Commit 21fb800

Browse files
committed
big breaking changes
1 parent 9ee1e7b commit 21fb800

File tree

3 files changed

+133
-7
lines changed

3 files changed

+133
-7
lines changed

backend/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
sudo systemctl stop uvicorn
22
sudo systemctl stop celery
3-
/usr/bin/uv run python -m celery -A worker.tasks.queue purge -f
3+
/home/ubuntu/.local/bin/uv run python -m celery -A worker.tasks.queue purge -f
44
sudo systemctl restart celery
55
sudo systemctl start uvicorn

frontend/components/Hooks/useChanges.jsx

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,111 @@
11
import axios from "axios";
22
import useSWR from "swr";
33

4+
function serializeLocalToGlobal(localStock) {
5+
const {
6+
name,
7+
cusip,
8+
ticker,
9+
sector,
10+
industry,
11+
class: rights,
12+
shares_held,
13+
shares_held_str,
14+
market_value,
15+
market_value_str,
16+
sold,
17+
update,
18+
ratios,
19+
records,
20+
prices,
21+
report_time = "N/A",
22+
recent_price = "N/A",
23+
} = localStock;
24+
25+
const {
26+
portfolio_percent: portfolio_percentage,
27+
portfolio_str: portfolio_percentage_str,
28+
ownership_percent: ownership_percentage,
29+
ownership_str: ownership_percentage_str,
30+
} = ratios;
31+
32+
const { buy: buy_price, sold: sold_price } = prices;
33+
34+
const {
35+
time: buy_time,
36+
time_str: buy_time_str,
37+
series: buy_series,
38+
} = buy_price;
39+
40+
const sold_time = sold_price ? sold_price.time : "N/A";
41+
const sold_time_str = sold_price ? sold_price.time_str : "N/A";
42+
const sold_series = sold_price ? sold_price.series : "N/A";
43+
44+
const report_date =
45+
report_time !== "N/A" ? new Date(report_time * 1000) : "N/A";
46+
const report_date_str =
47+
report_time !== "N/A"
48+
? `Q${
49+
Math.floor(report_date.getMonth() / 3) + 1
50+
} ${report_date.getFullYear()}`
51+
: "N/A";
52+
53+
const price_bought = buy_series !== "N/A" ? buy_series.close : "N/A";
54+
const price_bought_str = buy_series !== "N/A" ? `$${price_bought}` : "N/A";
55+
56+
const price_sold = sold_series !== "N/A" ? sold_series.close : "N/A";
57+
const price_sold_str = sold_series !== "N/A" ? `$${price_sold}` : "N/A";
58+
59+
const recent_price_str = recent_price !== "N/A" ? `$${recent_price}` : "N/A";
60+
61+
const gain_value =
62+
recent_price !== "N/A" && price_bought !== "N/A"
63+
? parseFloat(recent_price - price_bought)
64+
: "N/A";
65+
const gain_percent =
66+
gain_value !== "N/A" && price_bought !== "N/A"
67+
? parseFloat((gain_value / price_bought) * 100)
68+
: "N/A";
69+
const gain_value_str = gain_value !== "N/A" ? gain_value.toFixed(2) : "N/A";
70+
const gain_percent_str =
71+
gain_percent !== "N/A" ? gain_percent.toFixed(2) : "N/A";
72+
73+
return {
74+
name,
75+
cusip,
76+
ticker,
77+
sector,
78+
industry,
79+
class: rights,
80+
update,
81+
sold,
82+
recent_price,
83+
recent_price_str,
84+
buy_price: price_bought,
85+
buy_price_str: price_bought_str,
86+
sold_price: price_sold,
87+
sold_price_str: price_sold_str,
88+
shares_held,
89+
shares_held_str,
90+
market_value,
91+
market_value_str,
92+
portfolio_percent: portfolio_percentage,
93+
portfolio_str: portfolio_percentage_str,
94+
ownership_percent: ownership_percentage,
95+
ownership_str: ownership_percentage_str,
96+
gain_value,
97+
gain_value_str,
98+
gain_percent,
99+
gain_str: gain_percent_str,
100+
report_time,
101+
report_str: report_date_str,
102+
buy_time,
103+
buy_str: buy_time_str,
104+
sold_time,
105+
sold_str: sold_time_str,
106+
};
107+
}
108+
4109
const server = process.env.NEXT_PUBLIC_SERVER;
5110
const useChanges = (
6111
cik,
@@ -51,7 +156,7 @@ const useChanges = (
51156
})
52157
.catch((e) => console.error(e));
53158
const { isLoading: loading, error } = useSWR(
54-
cik && access ? [server + "/stocks/filing", cik, access, sort] : null,
159+
cik && access ? [server + "/stocks/changes", cik, access, sort] : null,
55160
([url, cik, access, sort]) => stockFetcher(url, cik, access, sort),
56161
{
57162
revalidateOnFocus: false,

frontend/redux/filerSlice.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ const initialComparisons = initialHeaders.map((h) => {
143143
return h;
144144
}
145145
});
146+
const initialChanges = [
147+
...initialComparisons,
148+
{ display: "Value", sort: "value", accessor: "value", active: true },
149+
];
146150
const initialSort = {
147151
sort: "ticker",
148152
type: "string",
@@ -163,9 +167,9 @@ const initialState = {
163167
sort: initialSort,
164168
filings: [],
165169
timeline: {
166-
comparisons: ["primary", "secondary", "main", "buy", "sell"].map(
167-
(order) => {
168-
// Main is shoe-horned in here. It should be its own slice, but this is easier.
170+
comparisons: [
171+
...["primary", "secondary", "main"].map((order) => {
172+
// Main is shoe-horned in here. It should be its own slice, but this is easier. Same story for everything except primary and secondary.
169173
return {
170174
type: order,
171175
access: "",
@@ -181,8 +185,25 @@ const initialState = {
181185
sort: initialSort,
182186
stocks: [],
183187
};
184-
}
185-
),
188+
}),
189+
...["buy", "sell"].map((order) => {
190+
return {
191+
type: order,
192+
access: "",
193+
filing: {
194+
time: 0,
195+
date: "",
196+
},
197+
report: {
198+
time: 0,
199+
date: "",
200+
},
201+
headers: initialComparisons,
202+
sort: initialSort,
203+
stocks: [],
204+
};
205+
}),
206+
],
186207
open: false,
187208
},
188209
difference: {

0 commit comments

Comments
 (0)