Scoring types, components alias, increase height, vertical app

This commit is contained in:
2024-12-13 21:58:18 -06:00
parent eb9d4cf572
commit 6f0b2050ad
10 changed files with 221 additions and 24 deletions

15
api/score.go Executable file
View File

@@ -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
}

10
app.go
View File

@@ -31,7 +31,7 @@ func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s, It's show time!", name) return fmt.Sprintf("Hello %s, It's show time!", name)
} }
func old() { func (a *App) Search() []api.ScoredOffer {
logger, _ := zap.NewDevelopment() logger, _ := zap.NewDevelopment()
defer logger.Sync() defer logger.Sync()
@@ -61,11 +61,5 @@ func old() {
sugar.Fatal(err) sugar.Fatal(err)
} }
// Print offers return api.ScoreOffers(resp.Offers)
sugar.Infof("Offers: %d", len(resp.Offers))
for _, offer := range resp.Offers {
sugar.Info(offer.String())
}
sugar.Info("Done")
} }

View File

@@ -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"; import { useEffect, useState } from "react";
function App() { function App() {
const [state, setState] = useState<string>(""); const [state, setState] = useState<api.ScoredOffer[] | null>(null);
async function invoke() {
const offers = await Search();
console.log({ offer: offers[0] });
setState(offers);
}
useEffect(() => { useEffect(() => {
Greet("World").then((result) => { if (state === null) invoke();
setState(result);
});
}); });
return ( return (
<div id="App"> <div id="App">
<div className="p-4">{state}</div> <div className="p-4" onClick={invoke}>
{state?.map((offer) => (
<Offer offer={offer} />
))}
</div>
</div> </div>
); );
} }

View File

@@ -1,7 +1,9 @@
export default function Offer() { import { api } from "@wails/go/models";
return (
<div className="p-4"> export default function Offer({
<h1>Offer</h1> offer: scoredOffer,
</div> }: {
); offer: api.ScoredOffer;
}) {
return <div className="p-4">{scoredOffer.Score}</div>;
} }

View File

@@ -3,5 +3,5 @@
@tailwind utilities; @tailwind utilities;
html { 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;
} }

View File

@@ -9,7 +9,7 @@ export default defineConfig({
plugins: [react()], plugins: [react()],
resolve: { resolve: {
alias: { alias: {
"@": rootPath + "src", "@components": rootPath + "src/components",
"@wails": rootPath + "wailsjs", "@wails": rootPath + "wailsjs",
}, },
}, },

View File

@@ -1,4 +1,7 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT // This file is automatically generated. DO NOT EDIT
import {api} from '../models';
export function Greet(arg1:string):Promise<string>; export function Greet(arg1:string):Promise<string>;
export function Search():Promise<Array<api.ScoredOffer>>;

View File

@@ -5,3 +5,7 @@
export function Greet(arg1) { export function Greet(arg1) {
return window['go']['main']['App']['Greet'](arg1); return window['go']['main']['App']['Greet'](arg1);
} }
export function Search() {
return window['go']['main']['App']['Search']();
}

169
frontend/wailsjs/go/models.ts Executable file
View File

@@ -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;
}
}
}

View File

@@ -18,8 +18,8 @@ func main() {
// Create application with options // Create application with options
err := wails.Run(&options.App{ err := wails.Run(&options.App{
Title: "vastop", Title: "vastop",
Width: 1024, Width: 768,
Height: 768, Height: 960,
AssetServer: &assetserver.Options{ AssetServer: &assetserver.Options{
Assets: assets, Assets: assets,
}, },