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

Commit ba62a4a

Browse files
Add counters to outputComputePlan (#74)
* Add existing count to output * Fix done counter and test all * Change to TupleCount
1 parent 901a1fa commit ba62a4a

File tree

10 files changed

+79
-17
lines changed

10 files changed

+79
-17
lines changed

EXAMPLES.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,8 @@ peer chaincode invoke -n mycc -c '{"Args":["createComputePlan","{\"tag\":\"a tag
14051405
{
14061406
"aggregatetupleKeys": null,
14071407
"compositeTraintupleKeys": null,
1408-
"computePlanID": "8412c09c3ce47cc3f2f4b86d3cb96850bda82ca1c177fbd4f5d4919966db12cb",
1408+
"computePlanID": "c51b1a4fe5a6c5abe5595ed530fbf1a9d822e6f22c57a029102db82ae71b41e4",
1409+
"doneCount": 0,
14091410
"status": "todo",
14101411
"tag": "a tag is simply a string",
14111412
"testtupleKeys": [
@@ -1414,7 +1415,8 @@ peer chaincode invoke -n mycc -c '{"Args":["createComputePlan","{\"tag\":\"a tag
14141415
"traintupleKeys": [
14151416
"432fcffdf68892f5e4adeeed8bb618beaeaecf709f840671eca724a3e3109369",
14161417
"d23f8cf290b902417ae698d68e2c6835483521d54fcbece31208517759b7c299"
1417-
]
1418+
],
1419+
"tupleCount": 3
14181420
}
14191421
```
14201422
#### ------------ Query an ObjectiveLeaderboard ------------
@@ -1488,14 +1490,15 @@ Smart contract: `queryComputePlan`
14881490
```
14891491
##### Command peer example:
14901492
```bash
1491-
peer chaincode invoke -n mycc -c '{"Args":["queryComputePlan","{\"key\":\"8412c09c3ce47cc3f2f4b86d3cb96850bda82ca1c177fbd4f5d4919966db12cb\"}"]}' -C myc
1493+
peer chaincode invoke -n mycc -c '{"Args":["queryComputePlan","{\"key\":\"c51b1a4fe5a6c5abe5595ed530fbf1a9d822e6f22c57a029102db82ae71b41e4\"}"]}' -C myc
14921494
```
14931495
##### Command output:
14941496
```json
14951497
{
14961498
"aggregatetupleKeys": null,
14971499
"compositeTraintupleKeys": null,
1498-
"computePlanID": "8412c09c3ce47cc3f2f4b86d3cb96850bda82ca1c177fbd4f5d4919966db12cb",
1500+
"computePlanID": "c51b1a4fe5a6c5abe5595ed530fbf1a9d822e6f22c57a029102db82ae71b41e4",
1501+
"doneCount": 0,
14991502
"status": "todo",
15001503
"tag": "a tag is simply a string",
15011504
"testtupleKeys": [
@@ -1504,7 +1507,8 @@ peer chaincode invoke -n mycc -c '{"Args":["queryComputePlan","{\"key\":\"8412c0
15041507
"traintupleKeys": [
15051508
"432fcffdf68892f5e4adeeed8bb618beaeaecf709f840671eca724a3e3109369",
15061509
"d23f8cf290b902417ae698d68e2c6835483521d54fcbece31208517759b7c299"
1507-
]
1510+
],
1511+
"tupleCount": 3
15081512
}
15091513
```
15101514
##### Command peer example:
@@ -1517,7 +1521,8 @@ peer chaincode invoke -n mycc -c '{"Args":["queryComputePlans"]}' -C myc
15171521
{
15181522
"aggregatetupleKeys": null,
15191523
"compositeTraintupleKeys": null,
1520-
"computePlanID": "8412c09c3ce47cc3f2f4b86d3cb96850bda82ca1c177fbd4f5d4919966db12cb",
1524+
"computePlanID": "c51b1a4fe5a6c5abe5595ed530fbf1a9d822e6f22c57a029102db82ae71b41e4",
1525+
"doneCount": 0,
15211526
"status": "todo",
15221527
"tag": "a tag is simply a string",
15231528
"testtupleKeys": [
@@ -1526,7 +1531,8 @@ peer chaincode invoke -n mycc -c '{"Args":["queryComputePlans"]}' -C myc
15261531
"traintupleKeys": [
15271532
"432fcffdf68892f5e4adeeed8bb618beaeaecf709f840671eca724a3e3109369",
15281533
"d23f8cf290b902417ae698d68e2c6835483521d54fcbece31208517759b7c299"
1529-
]
1534+
],
1535+
"tupleCount": 3
15301536
}
15311537
]
15321538
```
@@ -1540,14 +1546,15 @@ Smart contract: `cancelComputePlan`
15401546
```
15411547
##### Command peer example:
15421548
```bash
1543-
peer chaincode invoke -n mycc -c '{"Args":["cancelComputePlan","{\"key\":\"8412c09c3ce47cc3f2f4b86d3cb96850bda82ca1c177fbd4f5d4919966db12cb\"}"]}' -C myc
1549+
peer chaincode invoke -n mycc -c '{"Args":["cancelComputePlan","{\"key\":\"c51b1a4fe5a6c5abe5595ed530fbf1a9d822e6f22c57a029102db82ae71b41e4\"}"]}' -C myc
15441550
```
15451551
##### Command output:
15461552
```json
15471553
{
15481554
"aggregatetupleKeys": null,
15491555
"compositeTraintupleKeys": null,
1550-
"computePlanID": "8412c09c3ce47cc3f2f4b86d3cb96850bda82ca1c177fbd4f5d4919966db12cb",
1556+
"computePlanID": "c51b1a4fe5a6c5abe5595ed530fbf1a9d822e6f22c57a029102db82ae71b41e4",
1557+
"doneCount": 0,
15511558
"status": "canceled",
15521559
"tag": "a tag is simply a string",
15531560
"testtupleKeys": [
@@ -1556,6 +1563,7 @@ peer chaincode invoke -n mycc -c '{"Args":["cancelComputePlan","{\"key\":\"8412c
15561563
"traintupleKeys": [
15571564
"432fcffdf68892f5e4adeeed8bb618beaeaecf709f840671eca724a3e3109369",
15581565
"d23f8cf290b902417ae698d68e2c6835483521d54fcbece31208517759b7c299"
1559-
]
1566+
],
1567+
"tupleCount": 3
15601568
}
15611569
```

chaincode/compute_plan.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ func cancelComputePlan(db *LedgerDB, args []string) (resp outputComputePlan, err
292292
func (cp *ComputePlan) Create(db *LedgerDB) (string, error) {
293293
ID := GetRandomHash()
294294
cp.AssetType = ComputePlanType
295+
cp.TupleCount = 1
295296
err := db.Add(ID, cp)
296297
if err != nil {
297298
return "", err
@@ -330,7 +331,7 @@ func (cp *ComputePlan) CheckNewTupleStatus(tupleStatus string) bool {
330331
return true
331332
case StatusDone:
332333
cp.DoneCount++
333-
if cp.DoneCount == cp.TuplesCount {
334+
if cp.DoneCount == cp.TupleCount {
334335
cp.Status = tupleStatus
335336
}
336337
return true

chaincode/compute_plan_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,52 @@ func TestCreateTagedEmptyComputePlan(t *testing.T) {
595595
assert.NoError(t, err)
596596
assert.Equal(t, tag, out.Tag)
597597
}
598+
599+
func TestComputePlanMetrics(t *testing.T) {
600+
scc := new(SubstraChaincode)
601+
mockStub := NewMockStubWithRegisterNode("substra", scc)
602+
registerItem(t, *mockStub, "aggregateAlgo")
603+
mockStub.MockTransactionStart("42")
604+
db := NewLedgerDB(mockStub)
605+
606+
out, err := createComputePlanInternal(db, defaultComputePlan)
607+
assert.NoError(t, err)
608+
checkComputePlanMetrics(t, db, out.ComputePlanID, 0, 3)
609+
610+
traintupleToDone(t, db, out.TraintupleKeys[0])
611+
checkComputePlanMetrics(t, db, out.ComputePlanID, 1, 3)
612+
613+
traintupleToDone(t, db, out.TraintupleKeys[1])
614+
checkComputePlanMetrics(t, db, out.ComputePlanID, 2, 3)
615+
616+
testtupleToDone(t, db, out.TesttupleKeys[0])
617+
checkComputePlanMetrics(t, db, out.ComputePlanID, 3, 3)
618+
}
619+
620+
func traintupleToDone(t *testing.T, db *LedgerDB, key string) {
621+
_, err := logStartTrain(db, assetToArgs(inputHash{Key: key}))
622+
assert.NoError(t, err)
623+
624+
success := inputLogSuccessTrain{}
625+
success.Key = key
626+
success.fillDefaults()
627+
_, err = logSuccessTrain(db, assetToArgs(success))
628+
assert.NoError(t, err)
629+
}
630+
func testtupleToDone(t *testing.T, db *LedgerDB, key string) {
631+
_, err := logStartTest(db, assetToArgs(inputHash{Key: key}))
632+
assert.NoError(t, err)
633+
634+
success := inputLogSuccessTest{}
635+
success.Key = key
636+
success.createDefault()
637+
_, err = logSuccessTest(db, assetToArgs(success))
638+
assert.NoError(t, err)
639+
}
640+
641+
func checkComputePlanMetrics(t *testing.T, db *LedgerDB, cpID string, doneCount, tupleCount int) {
642+
out, err := getOutComputePlan(db, cpID)
643+
assert.NoError(t, err)
644+
assert.Equal(t, doneCount, out.DoneCount)
645+
assert.Equal(t, tupleCount, out.TupleCount)
646+
}

chaincode/ledger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ type ComputePlan struct {
190190
Tag string `json:"tag"`
191191
TesttupleKeys []string `json:"testtupleKeys"`
192192
TraintupleKeys []string `json:"traintupleKeys"`
193-
TuplesCount int `json:"tuplesCount"`
193+
TupleCount int `json:"tupleCount"`
194194
}
195195

196196
// ---------------------------------------------------------------------------------

chaincode/ledger_db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (db *LedgerDB) Get(key string, object interface{}) error {
8080
if !ok {
8181
buff, err = db.cc.GetState(key)
8282
if err != nil || buff == nil {
83-
return errors.NotFound(err)
83+
return errors.NotFound(err, "no asset for key %s", key)
8484
}
8585
db.putTransactionState(key, buff)
8686
}

chaincode/output.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ type outputComputePlan struct {
299299
TesttupleKeys []string `json:"testtupleKeys"`
300300
Tag string `json:"tag"`
301301
Status string `json:"status"`
302+
TupleCount int `json:"tupleCount"`
303+
DoneCount int `json:"doneCount"`
302304
}
303305

304306
func (out *outputComputePlan) Fill(key string, in ComputePlan) {
@@ -309,6 +311,8 @@ func (out *outputComputePlan) Fill(key string, in ComputePlan) {
309311
out.TesttupleKeys = in.TesttupleKeys
310312
out.Status = in.Status
311313
out.Tag = in.Tag
314+
out.TupleCount = in.TupleCount
315+
out.DoneCount = in.DoneCount
312316
}
313317

314318
type outputPermissions struct {

chaincode/testtuple.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (testtuple *Testtuple) AddToComputePlan(db *LedgerDB, testtupleKey string)
191191
return err
192192
}
193193
computePlan.TesttupleKeys = append(computePlan.TesttupleKeys, testtupleKey)
194-
computePlan.TuplesCount++
194+
computePlan.TupleCount++
195195
computePlan.CheckNewTupleStatus(testtuple.Status)
196196
err = computePlan.Save(db, testtuple.ComputePlanID)
197197
if err != nil {

chaincode/traintuple.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (traintuple *Traintuple) AddToComputePlan(db *LedgerDB, inp inputTraintuple
149149
return err
150150
}
151151
computePlan.TraintupleKeys = append(computePlan.TraintupleKeys, traintupleKey)
152-
computePlan.TuplesCount++
152+
computePlan.TupleCount++
153153
computePlan.CheckNewTupleStatus(traintuple.Status)
154154
err = computePlan.Save(db, traintuple.ComputePlanID)
155155
if err != nil {

chaincode/traintuple_composite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (traintuple *CompositeTraintuple) AddToComputePlan(db *LedgerDB, inp inputC
182182
return err
183183
}
184184
computePlan.CompositeTraintupleKeys = append(computePlan.CompositeTraintupleKeys, traintupleKey)
185-
computePlan.TuplesCount++
185+
computePlan.TupleCount++
186186
computePlan.CheckNewTupleStatus(traintuple.Status)
187187
err = computePlan.Save(db, traintuple.ComputePlanID)
188188
if err != nil {

chaincode/tuple_aggregate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (tuple *Aggregatetuple) AddToComputePlan(db *LedgerDB, inp inputAggregatetu
153153
return err
154154
}
155155
computePlan.AggregatetupleKeys = append(computePlan.AggregatetupleKeys, traintupleKey)
156-
computePlan.TuplesCount++
156+
computePlan.TupleCount++
157157
computePlan.CheckNewTupleStatus(tuple.Status)
158158
err = computePlan.Save(db, tuple.ComputePlanID)
159159
if err != nil {

0 commit comments

Comments
 (0)