From 6f0b2050ad18d9869bab77b457fc2802a93483ce Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 13 Dec 2024 21:58:18 -0600 Subject: [PATCH] Scoring types, components alias, increase height, vertical app --- api/score.go | 15 +++ app.go | 10 +- frontend/src/App.tsx | 22 ++-- frontend/src/components/Offer.tsx | 14 +-- frontend/src/main.css | 2 +- frontend/vite.config.ts | 2 +- frontend/wailsjs/go/main/App.d.ts | 3 + frontend/wailsjs/go/main/App.js | 4 + frontend/wailsjs/go/models.ts | 169 ++++++++++++++++++++++++++++++ main.go | 4 +- 10 files changed, 221 insertions(+), 24 deletions(-) create mode 100755 api/score.go create mode 100755 frontend/wailsjs/go/models.ts diff --git a/api/score.go b/api/score.go new file mode 100755 index 0000000..d28b870 --- /dev/null +++ b/api/score.go @@ -0,0 +1,15 @@ +package api + +type ScoredOffer struct { + Offer Offer + Score float64 +} + +func ScoreOffers(offers []Offer) []ScoredOffer { + var scoredOffers = make([]ScoredOffer, 0, len(offers)) + for _, offer := range offers { + score := 100.0 + scoredOffers = append(scoredOffers, ScoredOffer{Offer: offer, Score: score}) + } + return scoredOffers +} diff --git a/app.go b/app.go index bf54815..284b72f 100755 --- a/app.go +++ b/app.go @@ -31,7 +31,7 @@ func (a *App) Greet(name string) string { return fmt.Sprintf("Hello %s, It's show time!", name) } -func old() { +func (a *App) Search() []api.ScoredOffer { logger, _ := zap.NewDevelopment() defer logger.Sync() @@ -61,11 +61,5 @@ func old() { sugar.Fatal(err) } - // Print offers - sugar.Infof("Offers: %d", len(resp.Offers)) - for _, offer := range resp.Offers { - sugar.Info(offer.String()) - } - - sugar.Info("Done") + return api.ScoreOffers(resp.Offers) } diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index f9890ab..274c215 100755 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,18 +1,28 @@ -import { Greet } from "@wails/go/main/App"; +import Offer from "@components/Offer"; +import { Search } from "@wails/go/main/App"; +import { api } from "@wails/go/models"; import { useEffect, useState } from "react"; function App() { - const [state, setState] = useState(""); + const [state, setState] = useState(null); + + async function invoke() { + const offers = await Search(); + console.log({ offer: offers[0] }); + setState(offers); + } useEffect(() => { - Greet("World").then((result) => { - setState(result); - }); + if (state === null) invoke(); }); return (
-
{state}
+
+ {state?.map((offer) => ( + + ))} +
); } diff --git a/frontend/src/components/Offer.tsx b/frontend/src/components/Offer.tsx index 6277abb..f010846 100755 --- a/frontend/src/components/Offer.tsx +++ b/frontend/src/components/Offer.tsx @@ -1,7 +1,9 @@ -export default function Offer() { - return ( -
-

Offer

-
- ); +import { api } from "@wails/go/models"; + +export default function Offer({ + offer: scoredOffer, +}: { + offer: api.ScoredOffer; +}) { + return
{scoredOffer.Score}
; } diff --git a/frontend/src/main.css b/frontend/src/main.css index 75ffee7..6e418dd 100755 --- a/frontend/src/main.css +++ b/frontend/src/main.css @@ -3,5 +3,5 @@ @tailwind utilities; html { - @apply bg-zinc-800 p-0 m-0 h-screen w-screen text-zinc-200; + @apply bg-zinc-800 p-0 m-0 h-screen w-screen text-zinc-200 overflow-x-hidden; } diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index e81140b..bc2340a 100755 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -9,7 +9,7 @@ export default defineConfig({ plugins: [react()], resolve: { alias: { - "@": rootPath + "src", + "@components": rootPath + "src/components", "@wails": rootPath + "wailsjs", }, }, diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 02a3bb9..21a59cf 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -1,4 +1,7 @@ // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // This file is automatically generated. DO NOT EDIT +import {api} from '../models'; export function Greet(arg1:string):Promise; + +export function Search():Promise>; diff --git a/frontend/wailsjs/go/main/App.js b/frontend/wailsjs/go/main/App.js index c71ae77..9d57b50 100755 --- a/frontend/wailsjs/go/main/App.js +++ b/frontend/wailsjs/go/main/App.js @@ -5,3 +5,7 @@ export function Greet(arg1) { return window['go']['main']['App']['Greet'](arg1); } + +export function Search() { + return window['go']['main']['App']['Search'](); +} diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts new file mode 100755 index 0000000..92b61de --- /dev/null +++ b/frontend/wailsjs/go/models.ts @@ -0,0 +1,169 @@ +export namespace api { + + export class Offer { + is_bid: boolean; + inet_up_billed?: number; + inet_down_billed?: number; + external: boolean; + webpage?: string; + logo: string; + rentable: boolean; + compute_cap: number; + driver_version: string; + cuda_max_good: number; + machine_id: number; + hosting_type?: number; + public_ipaddr: string; + geolocation: string; + geolocode?: number; + flops_per_dphtotal: number; + dlperf_per_dphtotal: number; + reliability2: number; + host_run_time: number; + host_id: number; + id: number; + bundle_id: number; + num_gpus: number; + total_flops: number; + min_bid: number; + dph_base: number; + dph_total: number; + gpu_name: string; + gpu_ram: number; + gpu_display_active: boolean; + gpu_mem_bw: number; + bw_nvlink: number; + direct_port_count: number; + gpu_lanes: number; + pcie_bw: number; + pci_gen: number; + dlperf: number; + cpu_name: string; + mobo_name: string; + cpu_ram: number; + cpu_cores: number; + cpu_cores_effective: number; + gpu_frac: number; + has_avx: number; + disk_space: number; + disk_name: string; + disk_bw: number; + inet_up: number; + inet_down: number; + start_date: number; + end_date?: number; + duration?: number; + storage_cost: number; + inet_up_cost: number; + inet_down_cost: number; + storage_total_cost: number; + verification: string; + score: number; + rented: boolean; + bundled_results: number; + pending_count: number; + + static createFrom(source: any = {}) { + return new Offer(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.is_bid = source["is_bid"]; + this.inet_up_billed = source["inet_up_billed"]; + this.inet_down_billed = source["inet_down_billed"]; + this.external = source["external"]; + this.webpage = source["webpage"]; + this.logo = source["logo"]; + this.rentable = source["rentable"]; + this.compute_cap = source["compute_cap"]; + this.driver_version = source["driver_version"]; + this.cuda_max_good = source["cuda_max_good"]; + this.machine_id = source["machine_id"]; + this.hosting_type = source["hosting_type"]; + this.public_ipaddr = source["public_ipaddr"]; + this.geolocation = source["geolocation"]; + this.geolocode = source["geolocode"]; + this.flops_per_dphtotal = source["flops_per_dphtotal"]; + this.dlperf_per_dphtotal = source["dlperf_per_dphtotal"]; + this.reliability2 = source["reliability2"]; + this.host_run_time = source["host_run_time"]; + this.host_id = source["host_id"]; + this.id = source["id"]; + this.bundle_id = source["bundle_id"]; + this.num_gpus = source["num_gpus"]; + this.total_flops = source["total_flops"]; + this.min_bid = source["min_bid"]; + this.dph_base = source["dph_base"]; + this.dph_total = source["dph_total"]; + this.gpu_name = source["gpu_name"]; + this.gpu_ram = source["gpu_ram"]; + this.gpu_display_active = source["gpu_display_active"]; + this.gpu_mem_bw = source["gpu_mem_bw"]; + this.bw_nvlink = source["bw_nvlink"]; + this.direct_port_count = source["direct_port_count"]; + this.gpu_lanes = source["gpu_lanes"]; + this.pcie_bw = source["pcie_bw"]; + this.pci_gen = source["pci_gen"]; + this.dlperf = source["dlperf"]; + this.cpu_name = source["cpu_name"]; + this.mobo_name = source["mobo_name"]; + this.cpu_ram = source["cpu_ram"]; + this.cpu_cores = source["cpu_cores"]; + this.cpu_cores_effective = source["cpu_cores_effective"]; + this.gpu_frac = source["gpu_frac"]; + this.has_avx = source["has_avx"]; + this.disk_space = source["disk_space"]; + this.disk_name = source["disk_name"]; + this.disk_bw = source["disk_bw"]; + this.inet_up = source["inet_up"]; + this.inet_down = source["inet_down"]; + this.start_date = source["start_date"]; + this.end_date = source["end_date"]; + this.duration = source["duration"]; + this.storage_cost = source["storage_cost"]; + this.inet_up_cost = source["inet_up_cost"]; + this.inet_down_cost = source["inet_down_cost"]; + this.storage_total_cost = source["storage_total_cost"]; + this.verification = source["verification"]; + this.score = source["score"]; + this.rented = source["rented"]; + this.bundled_results = source["bundled_results"]; + this.pending_count = source["pending_count"]; + } + } + export class ScoredOffer { + Offer: Offer; + Score: number; + + static createFrom(source: any = {}) { + return new ScoredOffer(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this.Offer = this.convertValues(source["Offer"], Offer); + this.Score = source["Score"]; + } + + convertValues(a: any, classs: any, asMap: boolean = false): any { + if (!a) { + return a; + } + if (a.slice && a.map) { + return (a as any[]).map(elem => this.convertValues(elem, classs)); + } else if ("object" === typeof a) { + if (asMap) { + for (const key of Object.keys(a)) { + a[key] = new classs(a[key]); + } + return a; + } + return new classs(a); + } + return a; + } + } + +} + diff --git a/main.go b/main.go index f04f5b2..e9e8063 100755 --- a/main.go +++ b/main.go @@ -18,8 +18,8 @@ func main() { // Create application with options err := wails.Run(&options.App{ Title: "vastop", - Width: 1024, - Height: 768, + Width: 768, + Height: 960, AssetServer: &assetserver.Options{ Assets: assets, },