-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: building block for encoding (#47)
* add manufacturers.json for mapping devices * feat: implement building block for encoding * feat(FE): implement building block for encoding * fix: product name should not contain manufacturer name
- Loading branch information
Showing
19 changed files
with
794 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import type { ActivityFile } from './activity' | ||
|
||
export class DecodeResult { | ||
err: string | null = null | ||
activities: Array<ActivityFile> | ||
decodeTook: number | ||
serializationTook: number | ||
totalElapsed: number | ||
|
||
constructor(json?: any) { | ||
const casted = json as DecodeResult | ||
|
||
this.err = casted?.err | ||
this.activities = casted?.activities | ||
this.decodeTook = casted?.decodeTook | ||
this.serializationTook = casted?.serializationTook | ||
this.totalElapsed = casted?.totalElapsed | ||
} | ||
} | ||
|
||
export class EncodeResult { | ||
err: string | null = null | ||
encodeTook: number | ||
serializationTook: number | ||
totalElapsed: number | ||
fileName: string | ||
fileType: string | ||
fileBytes: Uint8Array | ||
|
||
constructor(data?: any) { | ||
const casted = data as EncodeResult | ||
this.err = casted?.err | ||
this.encodeTook = casted?.encodeTook | ||
this.serializationTook = casted?.serializationTook | ||
this.totalElapsed = casted?.totalElapsed | ||
this.fileName = casted?.fileName | ||
this.fileType = casted?.fileType | ||
this.fileBytes = casted?.fileBytes | ||
} | ||
} | ||
|
||
export class ManufacturerListResult { | ||
manufacturers: Manufacturer[] = [] | ||
|
||
constructor(data?: any) { | ||
const casted = data as ManufacturerListResult | ||
this.manufacturers = casted?.manufacturers | ||
} | ||
} | ||
|
||
export class Manufacturer { | ||
id: number = 0 | ||
name: string = '' | ||
products: Product[] = [] | ||
|
||
constructor(data?: any) { | ||
const casted = data as Manufacturer | ||
this.id = casted?.id | ||
this.name = casted?.name | ||
this.products = casted?.products | ||
} | ||
} | ||
|
||
export class Product { | ||
id: number = 0 | ||
name: string = '' | ||
|
||
constructor(data?: any) { | ||
const casted = data as Product | ||
this.id = casted?.id | ||
this.name = casted?.name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package fit | ||
|
||
type Manufacturer struct { | ||
ID uint16 | ||
Name string | ||
Products []ManufacturerProduct | ||
} | ||
|
||
func (m *Manufacturer) ToMap() map[string]any { | ||
products := make([]any, len(m.Products)) | ||
for i := range m.Products { | ||
products[i] = m.Products[i].ToMap() | ||
} | ||
return map[string]any{ | ||
"id": uint16(m.ID), | ||
"name": m.Name, | ||
"products": products, | ||
} | ||
} | ||
|
||
type ManufacturerProduct struct { | ||
ID uint16 | ||
Name string | ||
} | ||
|
||
func (p *ManufacturerProduct) ToMap() map[string]any { | ||
return map[string]any{ | ||
"id": p.ID, | ||
"name": p.Name, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.