This repository has been archived by the owner on Aug 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestdata.go
158 lines (143 loc) · 4.71 KB
/
testdata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package main
import (
"fmt"
"log"
database "github.com/YaleOpenLab/opensolar/database"
utils "github.com/YaleOpenLab/opensolar/utils"
)
func InsertDummyData() error {
var err error
// populate database with dumym data
var project1 database.DBParams
var contract1 database.Project
var contract2 database.Project
var contract3 database.Project
var rec database.Recipient
allRecs, err := database.RetrieveAllRecipients()
if err != nil {
log.Fatal(err)
}
if len(allRecs) == 0 {
// there is no recipient right now, so create a dummy recipient
var err error
rec, err = database.NewRecipient("martin", "p", "x", "Martin")
if err != nil {
log.Fatal(err)
}
}
var inv database.Investor
allInvs, err := database.RetrieveAllInvestors()
if err != nil {
log.Fatal(err)
}
if len(allInvs) == 0 {
var err error
inv, err = database.NewInvestor("john", "p", "x", "John")
if err != nil {
log.Fatal(err)
}
err = inv.AddVotingBalance(100000)
// this function saves as well, so there's no need to save again
if err != nil {
log.Fatal(err)
}
}
// NewOriginator(uname string, pwd string, Name string, Address string, Description string)
newOriginator, err := database.NewOriginator("john", "p", "x", "John Doe", "14 ABC Street London", "This is a sample originator")
if err != nil {
log.Fatal(err)
}
c1, err := database.NewContractor("john", "p", "x", "John Doe", "14 ABC Street London", "This is a sample contractor")
if err != nil {
log.Println(err)
}
project1.Index = 1
project1.PanelSize = "100 1000 sq.ft homes each with their own private spaces for luxury"
project1.TotalValue = 14000
project1.Location = "India Basin, San Francisco"
project1.MoneyRaised = 0
project1.Metadata = "India Basin is an upcoming creative project based in San Francisco that seeks to invite innovators from all around to participate"
project1.INVAssetCode = ""
project1.DEBAssetCode = ""
project1.PBAssetCode = ""
project1.DateInitiated = utils.Timestamp()
project1.Years = 3
project1.ProjectRecipient = rec
contract1.Params = project1
contract1.Contractor = c1
contract1.Originator = newOriginator
contract1.Stage = 3
err = contract1.Save()
if err != nil {
return fmt.Errorf("Error inserting project into db")
}
project1.Index = 2
project1.PanelSize = "180 1200 sq.ft homes in a high rise building 0.1mi from Kendall Square"
project1.TotalValue = 30000
project1.Location = "Kendall Square, Boston"
project1.MoneyRaised = 0
project1.Metadata = "Kendall Square is set in the heart of Cambridge and is a popular startup IT hub"
project1.INVAssetCode = ""
project1.DEBAssetCode = ""
project1.PBAssetCode = ""
project1.DateInitiated = utils.Timestamp()
project1.Years = 5
project1.ProjectRecipient = rec
contract2.Params = project1
contract2.Contractor = c1
contract2.Originator = newOriginator
contract2.Stage = 3
err = contract2.Save()
if err != nil {
return fmt.Errorf("Error inserting project into db")
}
project1.Index = 3
project1.PanelSize = "260 1500 sq.ft homes set in a medieval cathedral style construction"
project1.TotalValue = 40000
project1.Location = "Trafalgar Square, London"
project1.MoneyRaised = 0
project1.Metadata = "Trafalgar Square is set in the heart of London's financial district, with big banks all over"
project1.INVAssetCode = ""
project1.DEBAssetCode = ""
project1.PBAssetCode = ""
project1.DateInitiated = utils.Timestamp()
project1.Years = 7
project1.ProjectRecipient = rec
contract3.Params = project1
contract3.Contractor = c1
contract3.Originator = newOriginator
contract3.Stage = 3
err = contract3.Save()
if err != nil {
return fmt.Errorf("Error inserting project into db")
}
pc, err := newOriginator.OriginContract("100 16x24 panels on a solar rooftop", 14000, "Puerto Rico", 5, "ABC School in XYZ peninsula", 1) // 1 is the idnex for martin
if err != nil {
log.Fatal(err)
}
_, err = database.RetrieveProject(pc.Params.Index)
if err != nil {
log.Fatal(err)
}
// Each contractor building off of this must reference the project index in their
// proposed contract to enable searchability of the bucket. And each contractor
// must build off of this in their proposed Contracts
// Contractor stuff below, competing contractor details follow
_, err = database.NewContractor("sam", "p", "x", "Samuel Jackson", "14 ABC Street London", "This is a competing contractor")
if err != nil {
log.Fatal(err)
}
_, err = database.NewOriginator("samuel", "p", "x", "Samuel L. Jackson", "ABC Street, London", "I am an originator")
if err != nil {
log.Fatal(err)
}
_, err = database.RetrieveAllContractEntities("originator")
if err != nil {
log.Fatal(err)
}
_, err = database.RetrieveAllContractEntities("contractor")
if err != nil {
log.Fatal(err)
}
return nil
}