Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #125 from SubstraFoundation/snake_case
Browse files Browse the repository at this point in the history
Snake case
  • Loading branch information
Kelvin-M authored Sep 16, 2020
2 parents db594f9 + 22e3d64 commit c5cd878
Show file tree
Hide file tree
Showing 14 changed files with 467 additions and 478 deletions.
584 changes: 292 additions & 292 deletions EXAMPLES.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion chaincode/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestGetTestDatasetKeys(t *testing.T) {
err := json.Unmarshal(resp.Payload, &payload)
assert.NoError(t, err)

v, ok := payload["testDataSampleKeys"]
v, ok := payload["test_data_sample_keys"]
assert.True(t, ok, "payload should contains the test dataSample keys")
assert.Contains(t, v, testDataSampleHash2, "testDataSampleKeys should contain the test dataSampleHash")
assert.NotContains(t, v, testDataSampleHash1, "testDataSampleKeys should not contains the train dataSampleHash")
Expand Down
104 changes: 52 additions & 52 deletions chaincode/input.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions chaincode/input_aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ package main

// inputAggregatetuple is the representation of input args to register an aggregate Tuple
type inputAggregatetuple struct {
AlgoKey string `validate:"required,len=64,hexadecimal" json:"algoKey"`
InModels []string `validate:"omitempty,dive,len=64,hexadecimal" json:"inModels"`
ComputePlanID string `validate:"omitempty" json:"computePlanID"`
AlgoKey string `validate:"required,len=64,hexadecimal" json:"algo_key"`
InModels []string `validate:"omitempty,dive,len=64,hexadecimal" json:"in_models"`
ComputePlanID string `validate:"omitempty" json:"compute_plan_id"`
Metadata map[string]string `validate:"lte=100,dive,keys,lte=50,endkeys,lte=100" json:"metadata"`
Rank string `validate:"omitempty" json:"rank"`
Tag string `validate:"omitempty,lte=64" json:"tag"`
Expand Down
18 changes: 9 additions & 9 deletions chaincode/input_composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ package main

// inputCompositeTraintuple is the representation of input args to register a composite Traintuple
type inputCompositeTraintuple struct {
AlgoKey string `validate:"required,len=64,hexadecimal" json:"algoKey"`
InHeadModelKey string `validate:"required_with=InTrunkModelKey,omitempty,len=64,hexadecimal" json:"inHeadModelKey"`
InTrunkModelKey string `validate:"required_with=InHeadModelKey,omitempty,len=64,hexadecimal" json:"inTrunkModelKey"`
OutTrunkModelPermissions inputPermissions `validate:"required" json:"OutTrunkModelPermissions"`
DataManagerKey string `validate:"required,len=64,hexadecimal" json:"dataManagerKey"`
DataSampleKeys []string `validate:"required,unique,gt=0,dive,len=64,hexadecimal" json:"dataSampleKeys"`
ComputePlanID string `validate:"omitempty" json:"computePlanID"`
AlgoKey string `validate:"required,len=64,hexadecimal" json:"algo_key"`
InHeadModelKey string `validate:"required_with=InTrunkModelKey,omitempty,len=64,hexadecimal" json:"in_head_model_key"`
InTrunkModelKey string `validate:"required_with=InHeadModelKey,omitempty,len=64,hexadecimal" json:"in_trunk_model_key"`
OutTrunkModelPermissions inputPermissions `validate:"required" json:"out_trunk_model_permissions"`
DataManagerKey string `validate:"required,len=64,hexadecimal" json:"data_manager_key"`
DataSampleKeys []string `validate:"required,unique,gt=0,dive,len=64,hexadecimal" json:"data_sample_keys"`
ComputePlanID string `validate:"omitempty" json:"compute_plan_id"`
Rank string `validate:"omitempty" json:"rank"`
Tag string `validate:"omitempty,lte=64" json:"tag"`
Metadata map[string]string `validate:"lte=100,dive,keys,lte=50,endkeys,lte=100" json:"metadata"`
Expand All @@ -34,6 +34,6 @@ type inputCompositeAlgo struct {

type inputLogSuccessCompositeTrain struct {
inputLog
OutHeadModel inputHash `validate:"required" json:"outHeadModel"`
OutTrunkModel inputHashDress `validate:"required" json:"outTrunkModel"`
OutHeadModel inputHash `validate:"required" json:"out_head_model"`
OutTrunkModel inputHashDress `validate:"required" json:"out_trunk_model"`
}
106 changes: 53 additions & 53 deletions chaincode/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,41 @@ type StatusUpdater interface {
// Objective is the representation of one of the element type stored in the ledger
type Objective struct {
Name string `json:"name"`
AssetType AssetType `json:"assetType"`
DescriptionStorageAddress string `json:"descriptionStorageAddress"`
AssetType AssetType `json:"asset_type"`
DescriptionStorageAddress string `json:"description_storage_address"`
Metrics *HashDressName `json:"metrics"`
Owner string `json:"owner"`
TestDataset *Dataset `json:"testDataset"`
TestDataset *Dataset `json:"test_dataset"`
Permissions Permissions `json:"permissions"`
Metadata map[string]string `json:"metadata"`
}

// DataManager is the representation of one of the elements type stored in the ledger
type DataManager struct {
Name string `json:"name"`
AssetType AssetType `json:"assetType"`
OpenerStorageAddress string `json:"openerStorageAddress"`
AssetType AssetType `json:"asset_type"`
OpenerStorageAddress string `json:"opener_storage_address"`
Type string `json:"type"`
Description *HashDress `json:"description"`
Owner string `json:"owner"`
ObjectiveKey string `json:"objectiveKey"`
ObjectiveKey string `json:"objective_key"`
Permissions Permissions `json:"permissions"`
Metadata map[string]string `json:"metadata"`
}

// DataSample is the representation of one of the element type stored in the ledger
type DataSample struct {
AssetType AssetType `json:"assetType"`
DataManagerKeys []string `json:"dataManagerKeys"`
AssetType AssetType `json:"asset_type"`
DataManagerKeys []string `json:"data_manager_keys"`
Owner string `json:"owner"`
TestOnly bool `json:"testOnly"`
}

// Algo is the representation of one of the element type stored in the ledger
type Algo struct {
Name string `json:"name"`
AssetType AssetType `json:"assetType"`
StorageAddress string `json:"storageAddress"`
AssetType AssetType `json:"asset_type"`
StorageAddress string `json:"storage_address"`
Description *HashDress `json:"description"`
Owner string `json:"owner"`
Permissions Permissions `json:"permissions"`
Expand All @@ -101,9 +101,9 @@ type AggregateAlgo struct {
// that are common to Traintuple, CompositeTraintuple and
// AggregateTuple
type GenericTuple struct {
AssetType AssetType `json:"assetType"`
AlgoKey string `json:"algoKey"`
ComputePlanID string `json:"computePlanID"`
AssetType AssetType `json:"asset_type"`
AlgoKey string `json:"algo_key"`
ComputePlanID string `json:"compute_plan_id"`
Creator string `json:"creator"`
Log string `json:"log"`
Metadata map[string]string `json:"metadata"`
Expand All @@ -114,79 +114,79 @@ type GenericTuple struct {

// Traintuple is the representation of one the element type stored in the ledger. It describes a training task occuring on the platform
type Traintuple struct {
AssetType AssetType `json:"assetType"`
AlgoKey string `json:"algoKey"`
ComputePlanID string `json:"computePlanID"`
AssetType AssetType `json:"asset_type"`
AlgoKey string `json:"algo_key"`
ComputePlanID string `json:"compute_plan_id"`
Creator string `json:"creator"`
Log string `json:"log"`
Metadata map[string]string `json:"metadata"`
Rank int `json:"rank"`
Status string `json:"status"`
Tag string `json:"tag"`
Dataset *Dataset `json:"dataset"`
InModelKeys []string `json:"inModels"`
OutModel *HashDress `json:"outModel"`
InModelKeys []string `json:"in_models"`
OutModel *HashDress `json:"out_model"`
Permissions Permissions `json:"permissions"`
}

// CompositeTraintuple is like a traintuple, but for composite model composition
type CompositeTraintuple struct {
AssetType AssetType `json:"assetType"`
AlgoKey string `json:"algoKey"`
ComputePlanID string `json:"computePlanID"`
AssetType AssetType `json:"asset_type"`
AlgoKey string `json:"algo_key"`
ComputePlanID string `json:"compute_plan_id"`
Creator string `json:"creator"`
Log string `json:"log"`
Metadata map[string]string `json:"metadata"`
Rank int `json:"rank"`
Status string `json:"status"`
Tag string `json:"tag"`
Dataset *Dataset `json:"dataset"`
InHeadModel string `json:"inHeadModel"`
InTrunkModel string `json:"inTrunkModel"`
OutHeadModel CompositeTraintupleOutHeadModel `json:"outHeadModel"`
OutTrunkModel CompositeTraintupleOutModel `json:"outTrunkModel"`
InHeadModel string `json:"in_head_model"`
InTrunkModel string `json:"in_trunk_model"`
OutHeadModel CompositeTraintupleOutHeadModel `json:"out_head_model"`
OutTrunkModel CompositeTraintupleOutModel `json:"out_trunk_model"`
}

// Aggregatetuple is like a traintuple, but for aggregate model composition
type Aggregatetuple struct {
AssetType AssetType `json:"assetType"`
AlgoKey string `json:"algoKey"`
ComputePlanID string `json:"computePlanID"`
AssetType AssetType `json:"asset_type"`
AlgoKey string `json:"algo_key"`
ComputePlanID string `json:"compute_plan_id"`
Creator string `json:"creator"`
Log string `json:"log"`
Metadata map[string]string `json:"metadata"`
Rank int `json:"rank"`
Status string `json:"status"`
Tag string `json:"tag"`
InModelKeys []string `json:"inModels"`
OutModel *HashDress `json:"outModel"`
InModelKeys []string `json:"in_models"`
OutModel *HashDress `json:"out_model"`
Permissions Permissions `json:"permissions"` // TODO (aggregate): what do permissions mean here?
Worker string `json:"worker"`
}

// CompositeTraintupleOutModel is the out-model of a CompositeTraintuple
type CompositeTraintupleOutModel struct {
OutModel *HashDress `json:"outModel"`
OutModel *HashDress `json:"out_model"`
Permissions Permissions `json:"permissions"`
}

// CompositeTraintupleOutHeadModel is the out-model of a CompositeTraintuple
type CompositeTraintupleOutHeadModel struct {
OutModel *Hash `json:"outModel"`
OutModel *Hash `json:"out_model"`
Permissions Permissions `json:"permissions"`
}

// Testtuple is the representation of one the element type stored in the ledger. It describes a training task occuring on the platform
type Testtuple struct {
AlgoKey string `json:"algo"`
AssetType AssetType `json:"assetType"`
AssetType AssetType `json:"asset_type"`
Certified bool `json:"certified"`
ComputePlanID string `json:"computePlanID"`
ComputePlanID string `json:"compute_plan_id"`
Creator string `json:"creator"`
Dataset *TtDataset `json:"dataset"`
Log string `json:"log"`
Metadata map[string]string `json:"metadata"`
TraintupleKey string `json:"traintupleKey"`
TraintupleKey string `json:"traintuple_key"`
ObjectiveKey string `json:"objective"`
Permissions Permissions `json:"permissions"`
Rank int `json:"rank"`
Expand All @@ -196,27 +196,27 @@ type Testtuple struct {

// ComputePlan is the ledger's representation of a compute plan.
type ComputePlan struct {
AggregatetupleKeys []string `json:"aggregatetupleKeys"`
AssetType AssetType `json:"assetType"`
CleanModels bool `json:"cleanModels"` // whether or not to delete intermediary models
CompositeTraintupleKeys []string `json:"compositeTraintupleKeys"`
IDToTrainTask map[string]TrainTask `json:"IDToTrainTask"`
AggregatetupleKeys []string `json:"aggregatetuple_keys"`
AssetType AssetType `json:"asset_type"`
CleanModels bool `json:"clean_models"` // whether or not to delete intermediary models
CompositeTraintupleKeys []string `json:"composite_traintuple_keys"`
IDToTrainTask map[string]TrainTask `json:"id_to_train_task"`
Metadata map[string]string `json:"metadata"`
State ComputePlanState `json:"-"` // "-" means this field is excluded from JSON (de)serialization
StateKey string `json:"stateKey"`
StateKey string `json:"state_key"`
Tag string `json:"tag"`
TesttupleKeys []string `json:"testtupleKeys"`
TraintupleKeys []string `json:"traintupleKeys"`
TesttupleKeys []string `json:"testtuple_keys"`
TraintupleKeys []string `json:"traintuple_keys"`
}

// ComputePlanState is the ledger's representation of the compute plan state.
// To minimize the size of every compute plan, update its state record under another
// key in the ledger. It will reduce the growing rate of the blockchain size.
type ComputePlanState struct {
DoneCount int `json:"doneCount"`
IntermediaryModelsInUse []string `json:"intermediaryModelsInUse"`
DoneCount int `json:"done_count"`
IntermediaryModelsInUse []string `json:"intermediary_models_in_use"`
Status string `json:"status"`
TupleCount int `json:"tupleCount"`
TupleCount int `json:"tuple_count"`
}

// TrainTask is represent the information for one tuple in a Compute Plan
Expand All @@ -237,27 +237,27 @@ type Hash struct {
// HashDress stores a hash and a Storage Address
type HashDress struct {
Hash string `json:"hash"`
StorageAddress string `json:"storageAddress"`
StorageAddress string `json:"storage_address"`
}

// HashDressName stores a hash, storage address and a name
type HashDressName struct {
Name string `json:"name"`
Hash string `json:"hash"`
StorageAddress string `json:"storageAddress"`
StorageAddress string `json:"storage_address"`
}

// Model stores the traintupleKey leading to the model, its hash and storage addressl
type Model struct {
TraintupleKey string `json:"traintupleKey"`
TraintupleKey string `json:"traintuple_key"`
Hash string `json:"hash"`
StorageAddress string `json:"storageAddress"`
StorageAddress string `json:"storage_address"`
}

// Dataset stores info about a dataManagerKey and a list of associated dataSample
type Dataset struct {
DataManagerKey string `json:"dataManagerKey"`
DataSampleKeys []string `json:"dataSampleKeys"`
DataManagerKey string `json:"data_manager_key"`
DataSampleKeys []string `json:"data_sample_keys"`
Metadata map[string]string `json:"metadata"`
Worker string `json:"worker"`
}
Expand All @@ -270,7 +270,7 @@ type Dataset struct {
type TtDataset struct {
Worker string `json:"worker"`
DataSampleKeys []string `json:"keys"`
OpenerHash string `json:"openerHash"`
OpenerHash string `json:"opener_hash"`
Perf float32 `json:"perf"`
}

Expand Down
2 changes: 1 addition & 1 deletion chaincode/ledger_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (db *LedgerDB) GetIndexKeys(index string, attributes []string) ([]string, e
// It fails if it does not exists or if it does not have an `AssetType` field.
func (db *LedgerDB) GetAssetType(key string) (AssetType, error) {
asset := struct {
AssetType AssetType `json:"assetType"`
AssetType AssetType `json:"asset_type"`
}{}
if err := db.Get(key, &asset); err != nil {
return asset.AssetType, err
Expand Down
4 changes: 2 additions & 2 deletions chaincode/mockstub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,12 +650,12 @@ func newCompositeKey(objectType string, attributes []string) (string, error) {
if err := validateCompositeKeyAttribute(objectType); err != nil {
return "", err
}
ck := compositeKeyNamespace + objectType + string(minUnicodeRuneValue)
ck := compositeKeyNamespace + objectType + string(rune(minUnicodeRuneValue))
for _, att := range attributes {
if err := validateCompositeKeyAttribute(att); err != nil {
return "", err
}
ck += att + string(minUnicodeRuneValue)
ck += att + string(rune(minUnicodeRuneValue))
}
return ck, nil
}
Expand Down
Loading

0 comments on commit c5cd878

Please sign in to comment.