updates
This commit is contained in:
parent
9ada121417
commit
2ca391f6fd
@ -28,22 +28,30 @@ var rawData = make(map[string]map[time.Time]float32)
|
|||||||
var datas = map[string]Datas{
|
var datas = map[string]Datas{
|
||||||
"CPIAUCSL": {
|
"CPIAUCSL": {
|
||||||
Name: "CPI USA BASE",
|
Name: "CPI USA BASE",
|
||||||
ProcessFunction: toPercent,
|
ProcessFunction: toPercentNeg,
|
||||||
},
|
},
|
||||||
"PCEPI": {
|
"PCEPI": {
|
||||||
Name: "PCECPI USA",
|
Name: "PCECPI USA",
|
||||||
ProcessFunction: toPercent,
|
ProcessFunction: toPercentNeg,
|
||||||
},
|
},
|
||||||
"M2SL": {
|
"M2SL": {
|
||||||
Name: "M2 USA",
|
Name: "M2 USA",
|
||||||
ProcessFunction: toPercent,
|
ProcessFunction: toPercentNeg,
|
||||||
},
|
},
|
||||||
"CP0000EZ19M086NEST": {
|
"CP0000EZ19M086NEST": {
|
||||||
Name: "HICP ECB",
|
Name: "HICP ECB",
|
||||||
ProcessFunction: toPercent,
|
ProcessFunction: toPercentNeg,
|
||||||
},
|
},
|
||||||
"MABMM301EZM189S": {
|
"MABMM301EZM189S": {
|
||||||
Name: "M3 ECB",
|
Name: "M3 ECB",
|
||||||
|
ProcessFunction: toPercentNeg,
|
||||||
|
},
|
||||||
|
"CBBTCUSD": {
|
||||||
|
Name: "Bitcoin",
|
||||||
|
ProcessFunction: toPercent,
|
||||||
|
},
|
||||||
|
"APU0000708111": {
|
||||||
|
Name: "Eggs",
|
||||||
ProcessFunction: toPercent,
|
ProcessFunction: toPercent,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -60,7 +68,59 @@ func Setup() {
|
|||||||
i18n.RegisterTranslations(Embed, "locales")
|
i18n.RegisterTranslations(Embed, "locales")
|
||||||
|
|
||||||
web.RegisterAppSetupFunc(func(a *fiber.App) {
|
web.RegisterAppSetupFunc(func(a *fiber.App) {
|
||||||
a.Get("/app/inflation", func(c *fiber.Ctx) error {
|
a.Get("app/inflation", func(c *fiber.Ctx) error {
|
||||||
|
processedData := make(map[string]map[time.Time]float32)
|
||||||
|
for id, data := range datas {
|
||||||
|
processedData[id] = data.ProcessFunction(rawData[id])
|
||||||
|
}
|
||||||
|
|
||||||
|
line := charts.NewLine()
|
||||||
|
|
||||||
|
startYear, endYear := getYearRange(processedData)
|
||||||
|
yearList := createYearList(startYear, endYear)
|
||||||
|
for seriesID, timeData := range processedData {
|
||||||
|
|
||||||
|
aggregatedData := aggregateDataByYear(timeData)
|
||||||
|
|
||||||
|
yAxisT := []opts.LineData{}
|
||||||
|
var useAmount float32 = 1
|
||||||
|
for _, year := range yearList {
|
||||||
|
if value, exists := aggregatedData[year]; exists {
|
||||||
|
|
||||||
|
current := (value / 100) * useAmount
|
||||||
|
useAmount = useAmount + current
|
||||||
|
yAxisT = append(yAxisT, opts.LineData{Value: useAmount})
|
||||||
|
} else {
|
||||||
|
yAxisT = append(yAxisT, opts.LineData{Value: nil})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line.AddSeries(datas[seriesID].Name, yAxisT)
|
||||||
|
}
|
||||||
|
|
||||||
|
line.SetXAxis(yearList)
|
||||||
|
|
||||||
|
line.SetGlobalOptions(
|
||||||
|
charts.WithTitleOpts(opts.Title{
|
||||||
|
Title: "Inflation",
|
||||||
|
Subtitle: "Copyright Tijl 2024",
|
||||||
|
}),
|
||||||
|
charts.WithDataZoomOpts(opts.DataZoom{
|
||||||
|
Orient: "horizontal",
|
||||||
|
Type: "slider",
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
rendered := line.RenderSnippet()
|
||||||
|
|
||||||
|
data := *web.Common(c)
|
||||||
|
data["Title"] = "tmp"
|
||||||
|
data["RenderedScript"] = template.JS(handleScriptElement(rendered.Script))
|
||||||
|
data["RenderedElement"] = template.HTML(rendered.Element)
|
||||||
|
return c.Render("apps/inflation/index", data, "layouts/base")
|
||||||
|
|
||||||
|
})
|
||||||
|
a.Get("/app/inflation/base", func(c *fiber.Ctx) error {
|
||||||
|
|
||||||
processedData := make(map[string]map[time.Time]float32)
|
processedData := make(map[string]map[time.Time]float32)
|
||||||
for id, data := range datas {
|
for id, data := range datas {
|
||||||
|
@ -52,6 +52,30 @@ func aggregateDataByYear(data map[time.Time]float32) map[int32]float32 {
|
|||||||
return aggregatedData
|
return aggregatedData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toPercentNeg(m map[time.Time]float32) map[time.Time]float32 {
|
||||||
|
var times []time.Time
|
||||||
|
for t := range m {
|
||||||
|
times = append(times, t)
|
||||||
|
}
|
||||||
|
sort.Slice(times, func(i, j int) bool {
|
||||||
|
return times[i].Before(times[j])
|
||||||
|
})
|
||||||
|
percentageChanges := make(map[time.Time]float32)
|
||||||
|
var previousValue float32
|
||||||
|
for i, t := range times {
|
||||||
|
currentValue := m[t]
|
||||||
|
if i == 0 {
|
||||||
|
percentageChanges[t] = 0
|
||||||
|
} else {
|
||||||
|
percentageChange := ((currentValue - previousValue) / previousValue) * 100
|
||||||
|
percentageChanges[t] = -percentageChange
|
||||||
|
}
|
||||||
|
previousValue = currentValue
|
||||||
|
}
|
||||||
|
|
||||||
|
return percentageChanges
|
||||||
|
}
|
||||||
|
|
||||||
func toPercent(m map[time.Time]float32) map[time.Time]float32 {
|
func toPercent(m map[time.Time]float32) map[time.Time]float32 {
|
||||||
var times []time.Time
|
var times []time.Time
|
||||||
for t := range m {
|
for t := range m {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<div class="text-white">
|
<div id="chart" class="text-white">
|
||||||
{{.RenderedElement}}
|
{{.RenderedElement}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -8,4 +8,15 @@
|
|||||||
const script = `{{.RenderedScript}}`;
|
const script = `{{.RenderedScript}}`;
|
||||||
eval(script);
|
eval(script);
|
||||||
};
|
};
|
||||||
|
window.onresize = function () {
|
||||||
|
document.querySelectorAll('canvas, div').forEach(
|
||||||
|
function (e) {
|
||||||
|
const instance = echarts.getInstanceByDom(e);
|
||||||
|
if (instance) {
|
||||||
|
instance.resize()
|
||||||
|
console.log(instance, "resize")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
<div><a hx-boost="true" href="/app/flags">flags</a></div>
|
<div><a hx-boost="true" href="/app/flags">flags</a></div>
|
||||||
<div><a hx-boost="true" href="/app/uploader">uploader</a></div>
|
<div><a hx-boost="true" href="/app/uploader">uploader</a></div>
|
||||||
|
<div><a href="/app/inflation">inflation (full time based)</a></div>
|
||||||
|
<div><a href="/app/inflation/base">inflation</a></div>
|
||||||
|
Loading…
Reference in New Issue
Block a user