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
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{% extends "data_explorer/table_entries_base.html" %}
{% block table_headers %}
{% table_header "id" "Hash:Type:ID" min_width=700 %}
{% table_header "from_address" "From" min_width=400 %}
{% table_header "from_address" "To" min_width=400 %}
{% table_header "id" "Hash:Type:ID" min_width=150 %}
{% table_header "from_address" "From" min_width=150 %}
{% table_header "from_address" "To" min_width=150 %}
{% table_header "chain" "Chain" min_width=150 %}
{% table_header "asset" "Asset" min_width=150 %}
{% table_header "amount" "Amount" min_width=150 %}
{% table_header "created_at_original" "Date" min_width=250 %}
{% endblock %}
{% block table_rows %}
<td>{% foreign_key_link entry %}</td>
<td>{% foreign_key_link entry truncate_chars=10 %}</td>
<td>
{% if entry.from_address.ens_name %}
{% foreign_key_link entry.from_address "ens_name" %}
{% else %}
{% foreign_key_link entry.from_address %}
{% foreign_key_link entry.from_address truncate_chars=10 %}
{% endif %}
</td>
<td>
{% if entry.to_address.ens_name %}
{% foreign_key_link entry.to_address "ens_name" %}
{% else %}
{% foreign_key_link entry.to_address %}
{% foreign_key_link entry.to_address truncate_chars=10 %}
{% endif %}
</td>
<td>{{ entry.chain }}</td>
Expand Down
10 changes: 5 additions & 5 deletions src/simmate/apps/ethereum/templates/ethereum/wallets/table.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% extends "data_explorer/table_entries_base.html" %}
{% block table_headers %}
{% table_header "id" "ETH Address" min_width=400 %}
{% table_header "id" "ETH Address" min_width=150 %}
{% table_header "ens_name" "ENS" min_width=200 %}
{% table_header "ethereum_balance" "ETH" min_width=200 %}
{% table_header "usdc_balance" "USDC" min_width=200 %}
{% table_header "ethereum_balance" "ETH" min_width=150 %}
{% table_header "usdc_balance" "USDC" min_width=150 %}
{% table_header "stablecoin_total_balance" "Total Stablecoins" min_width=200 %}
{% table_header "assets_total_value_usd" "Total Assets" min_width=200 %}
{% table_header "assets_total_value_usd" "Total Assets" min_width=150 %}
{% table_header "updated_at" "Updated" min_width=250 %}
{% endblock %}
{% block table_rows %}
<td>{% foreign_key_link entry %}</td>
<td>{% foreign_key_link entry truncate_chars=10 %}</td>
<td>
{% if entry.ens_name %}
<b>{{ entry.ens_name }}</b>
Expand Down
23 changes: 22 additions & 1 deletion src/simmate/apps/price_catalog/clients/fred.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ class FredClient:
"Electricity": "CUSR0000SEHF01", # or APU000072610
"Housing": "CSUSHPINSA",
"Consumer Price Index": "CPIAUCSL", # use for inflation metrics
#
# Producer Price Index (PPI):
# sections for "Industrial Chemicals" or "Chemicals and Allied Products"
# Make sure you look at this link to see the full tree of these tickers
# and how they relate to one another (some are subcategories of others)
# https://fred.stlouisfed.org/release/tables?rid=46&eid=142872#snid=142874
"Chemicals": "WPU06", # & Allied Products
"Industrial Chemicals": "WPU061",
#
"Inorganic Chemicals": "WPU0613",
"Organic Chemicals": "WPU0614",
"Industrial Gases": "WPU067903",
#
"Carbon": "WPU06790918", # Carbon Black
# "Carbon Dioxide": "WPU06790302",
"Nitrogen": "WPU06790303",
"Oxygen": "WPU06790304",
"Aluminum": "WPU06130209", # Aluminum containing compounds
# "Sulfuric Acid": "WPU0613020T1",
# "NaCl": "WPU06130271", # Rock Salt
# "Ethanol": "WPU06140341",
}

@classmethod
Expand All @@ -41,7 +62,7 @@ def get_data(cls, name: str):
@staticmethod
def get_ticker_data(ticker: str):
"""
Uses the Yahoo ticker value to grab data. Can be any ticker in the live site
Uses the FRED ticker value to grab data. Can be any ticker in the live site
such as `SPY` or `GOOGL`
"""
url = f"https://fred.stlouisfed.org/graph/fredgraph.csv?id={ticker}"
Expand Down
3 changes: 3 additions & 0 deletions src/simmate/apps/price_catalog/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from .priced_items_report import PricedItemsReport
88 changes: 88 additions & 0 deletions src/simmate/apps/price_catalog/components/priced_items_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-

from simmate.website.htmx.components import HtmxComponent

from ..models import PricedItem


class PricedItemsReport(HtmxComponent):

template_name = "price_catalog/priced_items/report.html"

item_names_options: list[str] = None # set in mount
# years_ago_norm_options: list[int] = PricedItem.years_ago_options

years_ago_norm_options = [
(1, "Δ1y"),
(5, "Δ5y"),
(10, "Δ10y"),
(25, "Δ25y"),
("max", "Max"),
]

def mount(self):

self.priced_item_id = self.request.resolver_match.kwargs["table_entry_id"]
self.priced_item = PricedItem.objects.get(id=self.priced_item_id)

self.item_names_options = list(
PricedItem.objects.values_list("name", flat=True).order_by("name").all()
)
self.form_data = {
"item_names": [], # ["S&P 500", "Gold"]
"use_percent": False,
"use_inflation_adj": False,
"years_ago_norm": "max",
}
self.process() # to create figure

def post_parse(self):
# BUG: checkbox field does not show in POST data when =False. This is
# normal HTML behavior to save on bandwidth, but causes a bug here.
if "use_percent" not in self.post_data.keys():
self.post_data["use_percent"] = False
if "use_inflation_adj" not in self.post_data.keys():
self.post_data["use_inflation_adj"] = False

def process(self):

if self.form_data["item_names"]:
self.figure = PricedItem.get_report_figure(
names=[self.priced_item.name] + self.form_data["item_names"],
years_ago_norm=(
self.form_data["years_ago_norm"]
if self.form_data["years_ago_norm"] != "max"
else None
),
percent=(
self.form_data["use_percent"]
if self.form_data["years_ago_norm"] != "max"
else None
),
inflation_adj=self.form_data["use_inflation_adj"],
)

elif self.form_data["years_ago_norm"] == "max":
self.figure = self.priced_item.get_price_figure(
inflation_adj=self.form_data["use_inflation_adj"],
)

else:
self.figure = self.priced_item.get_delta_figure(
years_ago=self.form_data["years_ago_norm"],
percent=self.form_data["use_percent"],
inflation_adj=self.form_data["use_inflation_adj"],
)

# -------------------------------------------------------------------------

def on_change_hook__item_names(self):
# bug-fix: when only one is selected, the value isn't put in a list
if isinstance(self.form_data["item_names"], str):
self.form_data["item_names"] = [self.form_data["item_names"]]

def on_change_hook__years_ago_norm(self):
if self.form_data["years_ago_norm"] != "max":
self.form_data["item_names"] = []
# self.form_data["use_percent"] = True
# self.form_data["use_inflation_adj"] = True
5 changes: 5 additions & 0 deletions src/simmate/apps/price_catalog/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

To quickly look up common chemicals & their prices, for "the big 3":
- Sigma-Aldrich (MilliporeSigma): https://www.sigmaaldrich.com/US/en/products/chemistry-and-biochemicals/lab-chemicals
- Fisher Scientific (Thermo Fisher Scientific): https://www.thermofisher.com/us/en/home/chemicals.html
- VWR International (Avantor): https://www.avantorsciences.com/us/en/products/chemicals
3 changes: 3 additions & 0 deletions src/simmate/apps/price_catalog/data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from .utilities import WIKIPEDIA_PRICES_OF_ELEMENTS_DATA
38 changes: 38 additions & 0 deletions src/simmate/apps/price_catalog/data/utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-

from pathlib import Path

import pandas


def load_wikipedia_data() -> pandas.DataFrame:
"""
Loads a snapshot dataset from the "Prices of chemical elements" page

This dataset was pulled from:
https://en.wikipedia.org/wiki/Prices_of_chemical_elements

Note, I used Gemini to web scrape bc I'm lazy. The following prompt was used
to generate the CSV file, and I spot checked only a little to confirm:

'''
Grab the table from this link and convert it to a CSV:
https://en.wikipedia.org/wiki/Prices_of_chemical_elements

The following should be done too:
- split the "abundance" column into two columns, one for mg/kg and one for total mass
- use "e" notation instead of "x10^" so that values are floats
- standardize numerical columns (e.g. convert ranges to single value and exclude any >, <, ~, etc symbols)
- leave a cell empty instead of using text like "Not traded"
- use the columns names of...
z, symbol, name, density_kg_l, abundance_mg_kg, total_mass_kg,
price_per_kg, price_per_l, year, source, notes
'''

"""
datafile = Path(__file__).parent / "wikipedia_prices_of_elements.csv"
data = pandas.read_csv(datafile)
return data


WIKIPEDIA_PRICES_OF_ELEMENTS_DATA = load_wikipedia_data()
124 changes: 124 additions & 0 deletions src/simmate/apps/price_catalog/data/wikipedia_prices_of_elements.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
z,symbol,name,density_kg_l,abundance_mg_kg,total_mass_kg,price_per_kg,price_per_l,year,source,notes
1,H,Hydrogen,0.00008988,1400.0,3.878e19,1.39,0.000125,2012,DOE Hydrogen,
1,"2H (D)",Deuterium,0.0001667,1.5e-5,4.155e11,13400.0,2.23,2020,CIL,
2,He,Helium,0.0001785,0.008,2.216e14,24.0,0.00429,2018,USGS MCS,
3,Li,Lithium,0.534,20.0,5.54e17,83.5,44.55,2020,SMM,
4,Be,Beryllium,1.85,2.8,7.756e16,857.0,1590.0,2020,ISE 2020,
5,B,Boron,2.34,10.0,2.77e17,3.68,8.62,2019,CEIC Data,
6,C,Carbon,2.267,200.0,5.54e18,0.122,0.28,2018,EIA Coal,
7,N,Nitrogen,0.0012506,19.0,5.263e17,0.14,0.000175,2001,Hypertextbook,
8,O,Oxygen,0.001429,461000.0,1.277e22,0.154,0.00022,2001,Hypertextbook,
9,F,Fluorine,0.001696,585.0,1.62e19,2.0,0.00338,2017,Echemi,
10,Ne,Neon,0.0008999,0.005,1.385e14,240.0,0.21,1999,Ullmann,
11,Na,Sodium,0.971,23600.0,6.537e20,3.0,2.91,2020,SMM,
12,Mg,Magnesium,1.738,23300.0,6.454e20,2.32,4.03,2019,Preismonitor,
13,Al,Aluminium,2.698,82300.0,2.28e21,1.79,4.84,2019,Preismonitor,
14,Si,Silicon,2.3296,282000.0,7.811e21,1.7,3.97,2019,Preismonitor,
15,P,Phosphorus,1.82,1050.0,2.909e19,2.69,4.9,2019,CEIC Data,
16,S,Sulfur,2.067,350.0,9.695e18,0.0926,0.191,2019,CEIC Data,
17,Cl,Chlorine,0.003214,145.0,4.075e18,0.082,0.00026,2013,CnAgri,
18,Ar,Argon,0.0017837,3.5,9.695e16,0.931,0.00166,2019,UNLV,
19,K,Potassium,0.862,20900.0,5.789e20,12.85,11.1,2020,SMM,
20,Ca,Calcium,1.54,41500.0,1.15e21,2.28,3.52,2020,SMM,
21,Sc,Scandium,2.989,22.0,6.094e17,3460.0,10300.0,2020,ISE 2020,
22,Ti,Titanium,4.54,5650.0,1.565e20,11.4,51.8,2020,SMM,
23,V,Vanadium,6.11,120.0,3.324e18,371.0,2265.0,2020,SMM,
24,Cr,Chromium,7.15,102.0,2.825e18,9.4,67.2,2019,Preismonitor,
25,Mn,Manganese,7.44,950.0,2.632e19,1.82,13.6,2019,Preismonitor,
26,Fe,Iron,7.874,56300.0,1.565e21,0.424,3.34,2020,SMM,
27,Co,Cobalt,8.86,25.0,6.925e17,32.8,291.0,2019,Preismonitor,
28,Ni,Nickel,8.912,84.0,2.327e18,13.9,124.0,2019,Preismonitor,
29,Cu,Copper,8.96,60.0,1.662e18,6.0,53.8,2019,Preismonitor,
30,Zn,Zinc,7.134,70.0,1.939e18,2.55,18.2,2019,Preismonitor,
31,Ga,Gallium,5.907,19.0,5.263e17,148.0,872.0,2019,Preismonitor,
32,Ge,Germanium,5.323,1.5,4.155e16,962.0,5125.0,2020,SMM,
33,As,Arsenic,5.776,1.8,4.986e16,1.155,6.675,2020,SMM,
34,Se,Selenium,4.809,0.05,1.385e15,21.4,103.0,2019,Preismonitor,
35,Br,Bromine,3.122,2.4,6.648e16,4.39,13.7,2019,CEIC Data,
36,Kr,Krypton,0.003733,1.0e-4,2.77e12,290.0,1.1,1999,Ullmann,
37,Rb,Rubidium,1.532,90.0,2.493e18,15500.0,23700.0,2018,USGS MCS,
38,Sr,Strontium,2.64,370.0,1.025e19,6.605,17.4,2019,ISE 2019,
39,Y,Yttrium,4.469,33.0,9.141e17,31.0,139.0,2019,Preismonitor,
40,Zr,Zirconium,6.506,165.0,4.571e18,36.4,236.5,2020,SMM,
41,Nb,Niobium,8.57,20.0,5.54e17,73.5,630.0,2020,SMM,
42,Mo,Molybdenum,10.22,1.2,3.324e16,40.1,410.0,2019,Preismonitor,
43,Tc,Technetium,11.5,3.0e-9,8.31e7,100000.0,1200000.0,2004,CRC Handbook,
43,"99mTc","Technetium-99m",11.5,3.0e-9,8.31e7,1.9e12,2.2e13,2008,NRC,
44,Ru,Ruthenium,12.37,0.001,2.77e13,10500.0,130000.0,2020,SMM,
45,Rh,Rhodium,12.41,0.001,2.77e13,147000.0,1820000.0,2019,Preismonitor,
46,Pd,Palladium,12.02,0.015,4.155e14,49500.0,595000.0,2019,Preismonitor,
47,Ag,Silver,10.501,0.075,2.0775e15,521.0,5470.0,2019,Preismonitor,
48,Cd,Cadmium,8.69,0.159,4.4043e15,2.73,23.8,2019,Preismonitor,
49,In,Indium,7.31,0.25,6.925e15,167.0,1220.0,2019,Preismonitor,
50,Sn,Tin,7.287,2.3,6.371e16,18.7,136.0,2019,Preismonitor,
51,Sb,Antimony,6.685,0.2,5.54e15,5.79,38.7,2019,Preismonitor,
52,Te,Tellurium,6.232,0.001,2.77e13,63.5,396.0,2019,Preismonitor,
53,I,Iodine,4.93,0.45,1.2465e16,35.0,173.0,2019,Industrial Minerals,
54,Xe,Xenon,0.005887,3.0e-5,8.31e11,1800.0,11.0,1999,Ullmann,
55,Cs,Caesium,1.873,3.0,8.31e16,61800.0,116000.0,2018,USGS MCS,
56,Ba,Barium,3.594,425.0,1.177e19,0.2605,0.938,2016,USGS MYB 2016,
57,La,Lanthanum,6.145,39.0,1.08e18,4.85,29.85,2020,SMM,
58,Ce,Cerium,6.77,66.5,1.84205e18,4.64,31.4,2020,SMM,
59,Pr,Praseodymium,6.773,9.2,2.5484e17,103.0,695.0,2019,Preismonitor,
60,Nd,Neodymium,7.007,41.5,1.14955e18,57.5,403.0,2019,Preismonitor,
61,"147Pm","Promethium-147",7.26,5.0e-14,1.385e3,460000.0,3400000.0,2003,Radiochemistry Society,
62,Sm,Samarium,7.52,7.05,1.95285e17,13.9,104.0,2019,Preismonitor,
63,Eu,Europium,5.243,2.0,5.54e16,31.4,165.0,2020,ISE 2020,
64,Gd,Gadolinium,7.895,6.2,1.7174e17,28.6,226.0,2020,ISE 2020,
65,Tb,Terbium,8.229,1.2,3.324e16,658.0,5410.0,2019,Preismonitor,
66,Dy,Dysprosium,8.55,5.2,1.4404e17,307.0,2630.0,2019,Preismonitor,
67,Ho,Holmium,8.795,1.3,3.601e16,57.1,503.0,2020,ISE 2020,
68,Er,Erbium,9.066,3.5,9.695e16,26.4,240.0,2020,ISE 2020,
69,Tm,Thulium,9.321,0.52,1.4404e16,3000.0,28000.0,2003,IMAR,
70,Yb,Ytterbium,6.965,3.2,8.864e16,17.1,119.0,2020,ISE 2020,
71,Lu,Lutetium,9.84,0.8,2.216e16,643.0,6330.0,2020,ISE 2020,
72,Hf,Hafnium,13.31,3.0,8.31e16,900.0,12000.0,2017,USGS MCS,
73,Ta,Tantalum,16.654,2.0,5.54e16,305.0,5080.0,2019,ISE 2019,
74,W,Tungsten,19.25,1.3,3.601e16,35.3,679.0,2019,Preismonitor,
75,Re,Rhenium,21.02,7.0e-4,1.939e13,3580.0,75300.0,2020,SMM,
76,Os,Osmium,22.61,0.002,5.54e13,30000.0,678000.0,2025,elementsales.com,
77,Ir,Iridium,22.56,0.001,2.77e13,144000.0,3276000.0,2025,Umicore,
78,Pt,Platinum,21.46,0.005,1.385e14,27800.0,596000.0,2019,Preismonitor,
79,Au,Gold,19.282,0.004,1.108e14,75430.0,1454441.0,2024,London gold fix,
80,Hg,Mercury,13.5336,0.085,2.3545e15,30.2,409.0,2017,USGS MCS,
81,Tl,Thallium,11.85,0.85,2.3545e16,4200.0,49800.0,2017,USGS MCS,
82,Pb,Lead,11.342,14.0,3.878e17,2.0,22.6,2019,Preismonitor,
83,Bi,Bismuth,9.807,0.009,2.493e14,6.36,62.4,2019,Preismonitor,
84,"209Po","Polonium-209",9.32,3.0e-16,8.31e0,4.92e13,4.58e14,2004,CRC Handbook (ORNL),
85,At,Astatine,7.0,3.0e-20,8.31e-4,,,,
86,Rn,Radon,0.00973,4.0e-13,1.108e4,,,,
87,Fr,Francium,1.87,1.0e-18,2.77e-2,,,,
88,Ra,Radium,5.5,9.0e-7,2.493e10,,,,
89,"225Ac","Actinium-225",10.07,1.0e-11,2.77e5,2.9e13,2.9e14,2004,CRC Handbook (ORNL),
90,Th,Thorium,11.72,9.6,2.6592e17,287.0,3360.0,2010,USGS MYB 2012,
91,Pa,Protactinium,15.37,1.4e-6,3.878e10,,,,
92,U,Uranium,18.95,2.7,7.479e16,101.0,1910.0,2018,EIA Uranium Marketing,
93,Np,Neptunium,20.45,3.0e-12,8.31e4,660000.0,13500000.0,2003,Pomona,
94,"239Pu","Plutonium-239",19.84,5.0e-14,1.385e3,6490000.0,129000000.0,2019,DOE OSTI,
95,"241Am","Americium-241",13.69,,,728000.0,9970000.0,1998,NWA,
95,"243Am","Americium-243",13.69,,,750000.0,10300000.0,2004,CRC Handbook (ORNL),
96,"244Cm","Curium-244",13.51,,,185000000.0,2.5e9,2004,CRC Handbook (ORNL),
96,"248Cm","Curium-248",13.51,,,1.6e11,2.16e12,2004,CRC Handbook (ORNL),
97,"249Bk","Berkelium-249",14.79,,,1.85e11,2.74e12,2004,CRC Handbook (ORNL),
98,"249Cf","Californium-249",15.1,,,1.85e11,2.79e12,2004,CRC Handbook (ORNL),
98,"252Cf","Californium-252",15.1,,,6.0e10,9.06e11,2004,CRC Handbook (ORNL),
99,Es,Einsteinium,8.84,,,,,,
100,Fm,Fermium,9.7,,,,,,
101,Md,Mendelevium,10.3,,,,,,
102,No,Nobelium,9.9,,,,,,
103,Lr,Lawrencium,15.6,,,,,,
104,Rf,Rutherfordium,23.2,,,,,,
105,Db,Dubnium,29.3,,,,,,
106,Sg,Seaborgium,35.0,,,,,,
107,Bh,Bohrium,37.1,,,,,,
108,Hs,Hassium,40.7,,,,,,
109,Mt,Meitnerium,37.4,,,,,,
110,Ds,Darmstadtium,34.8,,,,,,
111,Rg,Roentgenium,28.7,,,,,,
112,Cn,Copernicium,14.0,,,,,,
113,Nh,Nihonium,16.0,,,,,,
114,Fl,Flerovium,9.928,,,,,,
115,Mc,Moscovium,13.5,,,,,,
116,Lv,Livermorium,12.9,,,,,,
117,Ts,Tennessine,7.2,,,,,,
118,Og,Oganesson,7.0,,,,,,
Loading
Loading