本文整理匯總了Golang中github.com/eaciit/dbox.In函數的典型用法代碼示例。如果您正苦於以下問題:Golang In函數的具體用法?Golang In怎麽用?Golang In使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了In函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetData
func (s *ScenarioSimulation) GetData(k *knot.WebContext) interface{} {
k.Config.OutputType = knot.OutputJson
status := ""
msg := ""
res := []*ValueEquation{}
payloads := struct {
StartPeriod string
EndPeriod string
SelectedPlant []string
SelectedUnit []string
SelectedSimulation string
SelectedDescription string
}{}
e := k.GetPayload(&payloads)
if e != nil {
s.WriteLog(e)
}
start, _ := time.Parse(time.RFC3339, payloads.StartPeriod)
end, _ := time.Parse(time.RFC3339, payloads.EndPeriod)
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", start))
query = append(query, dbox.Lte("Dates", end))
if payloads.SelectedPlant != nil && len(payloads.SelectedPlant) > 0 {
query = append(query, dbox.In("Plant", payloads.SelectedPlant))
}
if payloads.SelectedUnit != nil && len(payloads.SelectedUnit) > 0 {
query = append(query, dbox.In("Unit", payloads.SelectedUnit))
}
csr, err := s.DB().Connection.NewQuery().From("ValueEquation").Select("Plant", "AvgNetGeneration", "VOMR", "TotalOutageDuration", "TotalDuration", "OperatingCost", "Revenue", "TotalLabourCost", "TotalMaterialCost", "TotalServicesCost", "TotalFuelCost").Where(query...).Cursor(nil)
if err != nil {
msg = err.Error()
status = "NOK"
} else {
status = "OK"
}
err = csr.Fetch(&res, 0, true)
defer csr.Close()
result := tk.M{}
result.Set("Status", status)
result.Set("Message", msg)
result.Set("Data", res)
return result
}
示例2: GetData
func (m *ValueEquationComparison) GetData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
m.SetPayLoad(k)
type DataValue struct {
Revenue float64 `json:'Revenue'`
MaintenanceCost float64 `json:'MaintenanceCost'`
OperatingCost float64 `json:'OperatingCost'`
NetGeneration float64 `json:'NetGeneration'`
}
result, Result := tk.M{}, []DataValue{}
c := ctx.Connection
ve := ValueEquation{}
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
if m.SelectedPlant != nil && len(m.SelectedPlant) > 0 {
query = append(query, dbox.In("Plant", m.SelectedPlant))
}
if m.SelectedUnit != nil && len(m.SelectedUnit) > 0 {
query = append(query, dbox.In("Unit", m.SelectedUnit))
}
if m.SelectedUnitGroup != "ALL" {
query = append(query, dbox.In("UnitGroup", m.SelectedUnitGroup))
}
csr, e := c.NewQuery().
Where(query...).
Aggr(dbox.AggrSum, "Revenue", "Revenue").
Aggr(dbox.AggrSum, "MaintenanceCost", "MaintenanceCost").
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
Aggr(dbox.AggrSum, "NetGeneration", "NetGeneration").
From(ve.TableName()).Cursor(nil)
e = csr.Fetch(&Result, 0, false)
if e != nil {
return nil, e
}
csr.Close()
result.Set("Index", m.Index)
result.Set("DataValue", Result)
return result, nil
}
示例3: LoginDo
func (u *UserModel) LoginDo(ctx *orm.DataContext, username string, password string) (*UserModel, bool) {
PasswordHash := GetMD5Hash(password)
found := false
query := []*dbox.Filter{}
query = append(query, dbox.In("UserName", username))
query = append(query, dbox.In("PasswordHash", PasswordHash))
csr, e := ctx.Connection.NewQuery().From(u.TableName()).Where(query...).Cursor(nil)
if e != nil {
return nil, found
}
result := []*UserModel{}
csr.Fetch(&result, 0, false)
csr.Close()
if len(result) > 0 {
found = true
for _, i := range result {
u = i
}
}
return u, found
}
示例4: GetUnitList
func (m *ValueEquationComparison) GetUnitList(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
m.SetPayLoad(k)
mup := MasterUnitPlant{}
result, UnitData := tk.M{}, []MasterUnitPlant{}
c := ctx.Connection
query := []*dbox.Filter{}
if m.SelectedPlant != nil && len(m.SelectedPlant) > 0 {
query = append(query, dbox.In("Plant", m.SelectedPlant))
}
csr, e := c.NewQuery().
Where(query...).Select("Unit").
From(mup.TableName()).Group("Unit").Cursor(nil)
e = csr.Fetch(&UnitData, 0, false)
if e != nil {
return nil, e
}
csr.Close()
result.Set("Index", m.Index)
result.Set("UnitData", UnitData)
return result, e
}
示例5: ConnectToDataSourceDB
func (d *DataSourceController) ConnectToDataSourceDB(payload toolkit.M) (int, []toolkit.M, *colonycore.DataBrowser, error) {
var hasLookup bool
toolkit.Println("payload : ", payload)
if payload.Has("haslookup") {
hasLookup = payload.Get("haslookup").(bool)
}
_id := toolkit.ToString(payload.Get("browserid", ""))
sort := payload.Get("sort")
search := payload.Get("search")
_ = search
take := toolkit.ToInt(payload.Get("take", ""), toolkit.RoundingAuto)
skip := toolkit.ToInt(payload.Get("skip", ""), toolkit.RoundingAuto)
TblName := toolkit.M{}
payload.Unset("browserid")
//sorter = ""
if sort != nil {
tmsort, _ := toolkit.ToM(sort.([]interface{})[0])
fmt.Printf("====== sort %#v\n", tmsort["dir"])
if tmsort["dir"] == "asc" {
sorter = tmsort["field"].(string)
} else if tmsort["dir"] == "desc" {
sorter = "-" + tmsort["field"].(string)
} else if tmsort["dir"] == nil {
sorter = " "
}
} else {
sorter = " "
}
dataDS := new(colonycore.DataBrowser)
err := colonycore.Get(dataDS, _id)
if err != nil {
return 0, nil, nil, err
}
dataConn := new(colonycore.Connection)
err = colonycore.Get(dataConn, dataDS.ConnectionID)
if err != nil {
return 0, nil, nil, err
}
if err := d.checkIfDriverIsSupported(dataConn.Driver); err != nil {
return 0, nil, nil, err
}
connection, err := helper.ConnectUsingDataConn(dataConn).Connect()
if err != nil {
return 0, nil, nil, err
}
if dataDS.QueryType == "" {
TblName.Set("from", dataDS.TableNames)
payload.Set("from", dataDS.TableNames)
} else if dataDS.QueryType == "Dbox" {
getTableName := toolkit.M{}
toolkit.UnjsonFromString(dataDS.QueryText, &getTableName)
payload.Set("from", getTableName.Get("from").(string))
if qSelect := getTableName.Get("select", "").(string); qSelect != "" {
payload.Set("select", getTableName.Get("select").(string))
}
} else if dataDS.QueryType == "SQL" {
var QueryString string
if dataConn.Driver == "mysql" || dataConn.Driver == "hive" {
QueryString = " LIMIT " + toolkit.ToString(take) + " OFFSET " + toolkit.ToString(skip)
} else if dataConn.Driver == "mssql" {
QueryString = " OFFSET " + toolkit.ToString(skip) + " ROWS FETCH NEXT " +
toolkit.ToString(take) + " ROWS ONLY "
} else if dataConn.Driver == "postgres" {
QueryString = " LIMIT " + toolkit.ToString(take) +
" OFFSET " + toolkit.ToString(skip)
}
stringQuery := toolkit.Sprintf("%s %s", dataDS.QueryText, QueryString)
payload.Set("freetext", stringQuery)
// toolkit.Println(stringQuery)
}
qcount, _ := d.parseQuery(connection.NewQuery(), TblName)
query, _ := d.parseQuery(connection.NewQuery() /*.Skip(skip).Take(take) .Order(sorter)*/, payload)
var selectfield string
for _, metadata := range dataDS.MetaData {
tField := metadata.Field
if payload.Has(tField) {
selectfield = toolkit.ToString(tField)
if toolkit.IsSlice(payload[tField]) {
query = query.Where(dbox.In(tField, payload[tField].([]interface{})...))
qcount = qcount.Where(dbox.In(tField, payload[tField].([]interface{})...))
} else if !toolkit.IsNilOrEmpty(payload[tField]) {
var hasPattern bool
for _, val := range querypattern {
if strings.Contains(toolkit.ToString(payload[tField]), val) {
hasPattern = true
}
}
if hasPattern {
query = query.Where(dbox.ParseFilter(toolkit.ToString(tField), toolkit.ToString(payload[tField]),
toolkit.ToString(metadata.DataType), ""))
//.........這裏部分代碼省略.........
示例6: filterCondition
func filterCondition(cond toolkit.M) *dbox.Filter {
fb := new(dbox.Filter)
for key, val := range cond {
if key == "$and" || key == "$or" {
afb := []*dbox.Filter{}
for _, sVal := range val.([]interface{}) {
rVal := sVal.(map[string]interface{})
mVal := toolkit.M{}
for rKey, mapVal := range rVal {
mVal.Set(rKey, mapVal)
}
afb = append(afb, filterCondition(mVal))
}
if key == "$and" {
fb = dbox.And(afb...)
} else {
fb = dbox.Or(afb...)
}
} else {
if toolkit.TypeName(val) == "map[string]interface {}" {
mVal := val.(map[string]interface{})
tomVal, _ := toolkit.ToM(mVal)
switch {
case tomVal.Has("$eq"):
fb = dbox.Eq(key, tomVal["$eq"])
case tomVal.Has("$ne"):
fb = dbox.Ne(key, tomVal["$ne"])
case tomVal.Has("$regex"):
fb = dbox.Contains(key, toolkit.ToString(tomVal["$regex"]))
case tomVal.Has("$gt"):
fb = dbox.Gt(key, tomVal["$gt"])
case tomVal.Has("$gte"):
fb = dbox.Gte(key, tomVal["$gte"])
case tomVal.Has("$lt"):
fb = dbox.Lt(key, tomVal["$lt"])
case tomVal.Has("$lte"):
fb = dbox.Lte(key, tomVal["$lte"])
case tomVal.Has("$in"):
tval := make([]interface{}, 0, 0)
if toolkit.TypeName(tomVal["$in"]) == "[]interface {}" {
for _, tin := range tomVal["$in"].([]interface{}) {
tval = append(tval, tin)
}
} else {
tval = append(tval, tomVal["$in"])
}
fb = dbox.In(key, tval...)
case tomVal.Has("$nin"):
tval := make([]interface{}, 0, 0)
if toolkit.TypeName(tomVal["$nin"]) == "[]interface {}" {
for _, tin := range tomVal["$nin"].([]interface{}) {
tval = append(tval, tin)
}
} else {
tval = append(tval, tomVal["$nin"])
}
fb = dbox.Nin(key, tval...)
}
} else {
fb = dbox.Eq(key, val)
}
}
}
return fb
}
示例7: Exec
func (q *Query) Exec(in toolkit.M) error {
setting, e := q.prepare(in)
commandType := setting["commandtype"].(string)
//toolkit.Printf("Command type: %s\n", commandType)
if e != nil {
return err.Error(packageName, modQuery, "Exec: "+commandType, e.Error())
}
if setting.GetString("commandtype") == dbox.QueryPartSelect {
return err.Error(packageName, modQuery, "Exec: "+commandType, "Exec is not working with select command, please use .Cursor instead")
}
q.Lock()
defer q.Unlock()
var dataM toolkit.M
var dataMs []toolkit.M
hasData := in.Has("data")
dataIsSlice := false
data := in.Get("data")
if toolkit.IsSlice(data) {
dataIsSlice = true
e = toolkit.Unjson(toolkit.Jsonify(data), dataMs)
if e != nil {
return err.Error(packageName, modQuery, "Exec: "+commandType, "Data encoding error: "+e.Error())
}
} else {
dataM, e = toolkit.ToM(data)
dataMs = append(dataMs, dataM)
if e != nil {
return err.Error(packageName, modQuery, "Exec: "+commandType, "Data encoding error: "+e.Error())
}
}
hasWhere := setting.Has("where")
where := setting.Get("where", []*dbox.Filter{}).([]*dbox.Filter)
if hasWhere && len(where) == 0 {
inWhere := in.Get("where")
if inWhere == nil {
hasWhere = false
where = nil
} else {
if !toolkit.IsSlice(inWhere) {
where = append(where, inWhere.(*dbox.Filter))
} else {
where = inWhere.([]*dbox.Filter)
}
}
}
if hasData && hasWhere == false && toolkit.HasMember([]interface{}{dbox.QueryPartInsert, dbox.QueryPartDelete,
dbox.QueryPartUpdate, dbox.QueryPartSave}, commandType) {
hasWhere = true
//toolkit.Println("check where")
if toolkit.IsSlice(data) {
ids := []interface{}{}
idField := ""
if idField == "" {
return err.Error(packageName, modQuery, "Exec: "+commandType, "Data send is a slice, but its element has no ID")
}
dataCount := toolkit.SliceLen(data)
for i := 0; i < dataCount; i++ {
dataI := toolkit.SliceItem(data, i)
if i == 0 {
idField = toolkit.IdField(dataI)
}
ids = append(ids, toolkit.Id(dataI))
}
where = []*dbox.Filter{dbox.In(idField, ids)}
} else {
idfield := "_id"
id := toolkit.Id(data)
if !toolkit.IsNilOrEmpty(id) {
where = []*dbox.Filter{dbox.Eq(idfield, id)}
} else {
where = nil
hasWhere = false
}
}
}
/*
toolkit.Printf("CommandType: %s HasData: %v HasWhere: %v Where: %s\n",
commandType, hasData, hasWhere, toolkit.JsonString(where))
*/
e = q.openFile(commandType)
//toolkit.Printf(commandType+" Open File, found record: %d\nData:%s\n", len(q.data), toolkit.JsonString(q.data))
if e != nil {
return err.Error(packageName, modQuery, "Exec: "+commandType, e.Error())
}
var indexes []interface{}
if hasWhere && commandType != dbox.QueryPartInsert {
whereIndex := dbox.Find(q.data, where)
indexes = toolkit.ToInterfaceArray(&whereIndex)
//toolkit.Printf("Where Index: %s Index:%s\n", toolkit.JsonString(whereIndex), toolkit.JsonString(indexes))
}
if commandType == dbox.QueryPartInsert {
if !hasData {
return err.Error(packageName, modQuery, "Exec: "+commandType, "Data is empty")
//.........這裏部分代碼省略.........
示例8: Initiate
func (c *HypothesisController) Initiate(k *knot.WebContext) interface{} {
k.Config.OutputType = knot.OutputJson
type ReturnValue struct {
PlantList []MasterPlant
PlantListH2 []MasterPlant
EQTypeList []MasterEquipmentType
MROElementList []MasterMROElement
OrderTypeList []MasterOrderType
ActivityTypeList []MasterActivityType
FailureCode []MasterFailureCode
UnitList []tk.M
}
var (
Result ReturnValue
e error
)
d := struct {
selectedPlant []string
}{}
e = k.GetPayload(&d)
// tk.Printf("d: %#v \n\n", d)
curr, _ := c.DB().Find(&MasterPlant{}, nil)
defer curr.Close()
e = curr.Fetch(&Result.PlantList, 0, false)
// tk.Printf("Result.PlantList: %#v \n\n", Result.PlantList)
filter := tk.M{}
filter.Set("where", dbox.Nin("Plant", "Qurayyah CC", "PP9"))
curr = nil
curr, e = c.DB().Find(&MasterPlant{}, filter)
e = curr.Fetch(&Result.PlantListH2, 0, false)
// tk.Printf("Result.PlantListH2: %#v \n\n", Result.PlantListH2)
curr = nil
curr, e = c.DB().Find(&MasterEquipmentType{}, nil)
e = curr.Fetch(&Result.EQTypeList, 0, false)
// tk.Printf("Result.EQTypeList: %#v \n\n", Result.EQTypeList)
curr = nil
curr, e = c.DB().Find(&MasterMROElement{}, nil)
e = curr.Fetch(&Result.MROElementList, 0, false)
// tk.Printf("Result.MROElementList: %#v \n\n", Result.MROElementList)
curr = nil
curr, e = c.DB().Find(&MasterOrderType{}, nil)
e = curr.Fetch(&Result.OrderTypeList, 0, false)
// tk.Printf("Result.OrderTypeList: %#v \n\n", Result.OrderTypeList)
curr = nil
curr, e = c.DB().Find(&MasterActivityType{}, nil)
e = curr.Fetch(&Result.ActivityTypeList, 0, false)
// tk.Printf("Result.ActivityTypeList: %#v \n\n", Result.ActivityTypeList)
curr = nil
curr, e = c.DB().Find(&MasterFailureCode{}, nil)
e = curr.Fetch(&Result.FailureCode, 0, false)
// tk.Printf("Result.FailureCode: %#v \n\n", Result.FailureCode)
var filter1 []*dbox.Filter
if len(d.selectedPlant) != 0 {
filter1 = append(filter1, dbox.In("Plant", d.selectedPlant))
} else {
filter1 = append(filter1, dbox.Eq("1", "1"))
}
/*pipes = append(pipes, tk.M{"$group": tk.M{
"_id": "$unit",
}})*/
curr = nil
curr, e = c.DB().Connection.NewQuery().
Select("Unit").
From(new(MasterUnitPlant).TableName()).
Where(filter1...).
Group("Unit").
Cursor(nil)
e = curr.Fetch(&Result.UnitList, 0, true)
// tk.Printf("Result.UnitList: %#v \n\n", Result.UnitList)
return ResultInfo(Result, e)
}
示例9: GetAssetWorkData
func (m *HistoricalValueEquation) GetAssetWorkData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
type DataValue struct {
ID string
Plant string `json:'Plant'`
Unit string `json:'Unit'`
ValueEquationCost float64 `json:'ValueEquationCost'`
MaxPowerGeneration float64 `json:'MaxPowerGeneration'`
PotentialRevenue float64 `json:'PotentialRevenue'`
NetGeneration float64 `json:'NetGeneration'`
Revenue float64 `json:'Revenue'`
ForcedOutages float64 `json:'ForcedOutages'`
ForcedOutagesLoss float64 `json:'ForcedOutagesLoss'`
UnforcedOutages float64 `json:'UnforcedOutages'`
UnforcedOutagesLoss float64 `json:'UnforcedOutagesLoss'`
TotalLabourCost float64 `json:'TotalLabourCost'`
TotalMaterialCost float64 `json:'TotalMaterialCost'`
TotalServicesCost float64 `json:'TotalServicesCost'`
MaintenanceCost float64 `json:'MaintenanceCost'`
OperatingCost float64 `json:'OperatingCost'`
}
m.SetPayLoad(k)
var e error = nil
result := []*DataValue{}
c := ctx.Connection
ve := ValueEquation{}
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
groupBy := "Plant"
switch m.Scope {
case "Kingdom":
break
case "Plant":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Plant", m.Selected))
}
groupBy = "Unit"
break
case "Phase":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Phase", m.Selected))
}
break
case "Unit":
query = append(query, dbox.Eq("Plant", m.SelectedPlant))
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Unit", m.Selected))
}
groupBy = "Unit"
break
default:
break
}
csr, e := c.NewQuery().
Where(query...).Select(groupBy).
Aggr(dbox.AggrSum, "ValueEquationCost", "ValueEquationCost").
Aggr(dbox.AggrSum, "MaxPowerGeneration", "MaxPowerGeneration").
Aggr(dbox.AggrSum, "PotentialRevenue", "PotentialRevenue").
Aggr(dbox.AggrSum, "NetGeneration", "NetGeneration").
Aggr(dbox.AggrSum, "Revenue", "Revenue").
Aggr(dbox.AggrSum, "ForcedOutages", "ForcedOutages").
Aggr(dbox.AggrSum, "ForcedOutagesLoss", "ForcedOutagesLoss").
Aggr(dbox.AggrSum, "UnforcedOutages", "UnforcedOutages").
Aggr(dbox.AggrSum, "UnforcedOutagesLoss", "UnforcedOutagesLoss").
Aggr(dbox.AggrSum, "TotalLabourCost", "TotalLabourCost").
Aggr(dbox.AggrSum, "TotalMaterialCost", "TotalMaterialCost").
Aggr(dbox.AggrSum, "TotalServicesCost", "TotalServicesCost").
Aggr(dbox.AggrSum, "MaintenanceCost", "MaintenanceCost").
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
From(ve.TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if csr != nil {
e = csr.Fetch(&result, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range result {
if i.Unit != "" {
i.ID = i.Unit
} else {
i.ID = i.Plant
}
}
return result, e
}
示例10: GetPerformanceData
func (m *HistoricalValueEquation) GetPerformanceData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
type DataValue struct {
ID string
Plant string `json:'Plant'`
Unit string `json:'Unit'`
NetGeneration float64 `json:'NetGeneration'`
PrctWAF float64 `json:'PrctWAF'`
}
m.SetPayLoad(k)
var e error = nil
result := []*DataValue{}
c := ctx.Connection
ve := ValueEquation{}
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
groupBy := "Plant"
switch m.Scope {
case "Kingdom":
break
case "Plant":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Plant", m.Selected))
}
groupBy = "Unit"
break
case "Phase":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Phase", m.Selected))
}
break
case "Unit":
query = append(query, dbox.Eq("Plant", m.SelectedPlant))
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Unit", m.Selected))
}
groupBy = "Unit"
break
default:
break
}
csr, e := c.NewQuery().
Where(query...).Select(groupBy).
Aggr(dbox.AggrSum, "NetGeneration", "NetGeneration").
Aggr(dbox.AggrAvr, "PrctWAF", "PrctWAF").
From(ve.TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if csr != nil {
e = csr.Fetch(&result, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range result {
if i.Unit != "" {
i.ID = i.Unit
} else {
i.ID = i.Plant
}
}
return result, e
}
示例11: GetDataQuality
func (m *HistoricalValueEquation) GetDataQuality(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
type DataValue struct {
ID string
Plant string `json:'Plant'`
Unit string `json:'Unit'`
Count float64 `json:'Count'`
CapacityPayment_Data float64 `json:'CapacityPayment_Data'`
EnergyPayment_Data float64 `json:'EnergyPayment_Data'`
StartupPayment_Data float64 `json:'StartupPayment_Data'`
Penalty_Data float64 `json:'Penalty_Data'`
Incentive_Data float64 `json:'Incentive_Data'`
MaintenanceCost_Data float64 `json:'MaintenanceCost_Data'`
MaintenanceDuration_Data float64 `json:'MaintenanceDuration_Data'`
PrimaryFuel1st_Data float64 `json:'PrimaryFuel1st_Data'`
PrimaryFuel2nd_Data float64 `json:'PrimaryFuel2nd_Data'`
BackupFuel_Data float64 `json:'BackupFuel_Data'`
FuelTransport_Data float64 `json:'FuelTransport_Data'`
}
m.SetPayLoad(k)
var e error = nil
result := []*DataValue{}
c := ctx.Connection
vedq := ValueEquationDataQuality{}
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
groupBy := "Plant"
switch m.Scope {
case "Kingdom":
break
case "Plant":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Plant", m.Selected))
}
groupBy = "Unit"
break
case "Phase":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Phase", m.Selected))
}
break
case "Unit":
query = append(query, dbox.Eq("Plant", m.SelectedPlant))
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Unit", m.Selected))
}
groupBy = "Unit"
break
default:
break
}
if m.Scope == "Unit" || (m.Scope == "Plant" && m.Selected != nil && len(m.Selected) == 1) {
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
if m.Scope == "Unit" {
query = append(query, dbox.Eq("Plant", m.SelectedPlant))
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Unit", m.Selected))
}
} else {
query = append(query, dbox.Eq("Plant", m.Selected[0]))
}
temp := []*ValueEquationDataQuality{}
csr, e := ctx.Find(new(ValueEquationDataQuality), tk.M{}.Set("where", dbox.And(query...)))
if csr != nil {
e = csr.Fetch(&temp, 0, false)
}
csr.Close()
if e != nil {
return nil, e
} else {
m.GetValueEquationDocument(ctx, temp)
return temp, e
}
} else {
csr, e := c.NewQuery().
Where(query...).Select(groupBy).
Aggr(dbox.AggrSum, "1", "Count").
Aggr(dbox.AggrSum, "CapacityPayment_Data", "CapacityPayment_Data").
Aggr(dbox.AggrSum, "EnergyPayment_Data", "EnergyPayment_Data").
Aggr(dbox.AggrSum, "StartupPayment_Data", "StartupPayment_Data").
Aggr(dbox.AggrSum, "Penalty_Data", "Penalty_Data").
Aggr(dbox.AggrSum, "Incentive_Data", "Incentive_Data").
Aggr(dbox.AggrSum, "MaintenanceCost_Data", "MaintenanceCost_Data").
Aggr(dbox.AggrSum, "MaintenanceDuration_Data", "MaintenanceDuration_Data").
Aggr(dbox.AggrSum, "PrimaryFuel1st_Data", "PrimaryFuel1st_Data").
Aggr(dbox.AggrSum, "PrimaryFuel2nd_Data", "PrimaryFuel2nd_Data").
Aggr(dbox.AggrSum, "BackupFuel_Data", "BackupFuel_Data").
Aggr(dbox.AggrSum, "FuelTransport_Data", "FuelTransport_Data").
From(vedq.TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if csr != nil {
e = csr.Fetch(&result, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
//.........這裏部分代碼省略.........
示例12: GetRevenueData
func (m *HistoricalValueEquation) GetRevenueData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
type DataValue struct {
ID string
Plant string `json:'Plant'`
Unit string `json:'Unit'`
CapacityPayment float64 `json:'CapacityPayment'`
EnergyPayment float64 `json:'EnergyPayment'`
StartupPayment float64 `json:'StartupPayment'`
PenaltyAmount float64 `json:'PenaltyAmount'`
Incentive float64 `json:'Incentive'`
Revenue float64 `json:'Revenue'`
}
m.SetPayLoad(k)
result, DataChartRevenue, DataChartRevenueEx := tk.M{}, []*DataValue{}, []*DataValue{}
c := ctx.Connection
ve := ValueEquation{}
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
groupBy := "Plant"
switch m.Scope {
case "Kingdom":
break
case "Plant":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Plant", m.Selected))
}
groupBy = "Unit"
break
case "Phase":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Phase", m.Selected))
}
break
case "Unit":
query = append(query, dbox.Eq("Plant", m.SelectedPlant))
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Unit", m.Selected))
}
groupBy = "Unit"
break
default:
break
}
csr, e := c.NewQuery().
Where(query...).
Aggr(dbox.AggrSum, "CapacityPayment", "CapacityPayment").
Aggr(dbox.AggrSum, "EnergyPayment", "EnergyPayment").
Aggr(dbox.AggrSum, "StartupPayment", "StartupPayment").
Aggr(dbox.AggrSum, "PenaltyAmount", "PenaltyAmount").
Aggr(dbox.AggrSum, "Incentive", "Incentive").
Aggr(dbox.AggrSum, "Revenue", "Revenue").
From(ve.TableName()).Cursor(nil)
if csr != nil {
e = csr.Fetch(&DataChartRevenue, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
csr, e = c.NewQuery().
Where(query...).Select(groupBy).
Aggr(dbox.AggrSum, "CapacityPayment", "CapacityPayment").
Aggr(dbox.AggrSum, "EnergyPayment", "EnergyPayment").
Aggr(dbox.AggrSum, "StartupPayment", "StartupPayment").
Aggr(dbox.AggrSum, "PenaltyAmount", "PenaltyAmount").
Aggr(dbox.AggrSum, "Incentive", "Incentive").
Aggr(dbox.AggrSum, "Revenue", "Revenue").
From(ve.TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if csr != nil {
e = csr.Fetch(&DataChartRevenueEx, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range DataChartRevenueEx {
if i.Unit != "" {
i.ID = i.Unit
} else {
i.ID = i.Plant
}
}
return result.Set("DataChartRevenue", DataChartRevenue).Set("DataChartRevenueEx", DataChartRevenueEx), e
}
示例13: GetOperatingData
func (m *HistoricalValueEquation) GetOperatingData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
type DataValue struct {
ID string
Plant string `json:'Plant'`
Unit string `json:'Unit'`
OperatingCost float64 `json:'OperatingCost'`
FuelTransportCost float64 `json:'FuelTransportCost'`
Capacity float64 `json:'Capacity'`
NetGeneration float64 `json:'NetGeneration'`
}
type DataTableType struct {
IsPrimaryFuel bool `json:'IsPrimaryFuel'`
FuelType string `json:'FuelType'`
ConvertedFuelConsumed float64 `json:'ConvertedFuelConsumed'`
FuelCostPerUnit float64 `json:'FuelCostPerUnit'`
FuelCost float64 `json:'FuelCost'`
}
m.SetPayLoad(k)
result, DataChart, DataTable, DataTotal, DataDetail := tk.M{}, []tk.M{}, []*DataTableType{}, []*DataValue{}, []*DataValue{}
c := ctx.Connection
ve := ValueEquation{}
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
groupBy := "Plant"
switch m.Scope {
case "Kingdom":
break
case "Plant":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Plant", m.Selected))
}
groupBy = "Unit"
break
case "Phase":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Phase", m.Selected))
}
break
case "Unit":
query = append(query, dbox.Eq("Plant", m.SelectedPlant))
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Unit", m.Selected))
}
groupBy = "Unit"
break
default:
break
}
// Getting "DataTable" - skip, need $unwind [ $Fuel ]
tempValueEquation := []ValueEquation{}
csr, e := c.NewQuery().
Where(query...).Select("Id").
From(ve.TableName()).Cursor(nil)
if csr != nil {
e = csr.Fetch(&tempValueEquation, 0, false)
}
csr.Close()
VEId := []interface{}{}
for _, i := range tempValueEquation {
VEId = append(VEId, i.Id)
}
csr, e = c.NewQuery().
Where(query...).
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
Aggr(dbox.AggrSum, "FuelTransportCost", "FuelTransportCost").
From(ve.TableName()).Cursor(nil)
if csr != nil {
e = csr.Fetch(&DataTotal, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
if m.Scope != "Unit" {
csr, e = c.NewQuery().
Where(query...).Select(groupBy).
Aggr(dbox.AggrSum, "Capacity", "Capacity").
Aggr(dbox.AggrSum, "NetGeneration", "NetGeneration").
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
From(ve.TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if csr != nil {
e = csr.Fetch(&DataDetail, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range DataDetail {
if i.Unit != "" {
i.ID = i.Unit
} else {
i.ID = i.Plant
}
}
//.........這裏部分代碼省略.........
示例14: GetMaintenanceData
func (m *HistoricalValueEquation) GetMaintenanceData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
m.SetPayLoad(k)
type DataValue struct {
ID string
DataSource string `json:'DataSource'`
WorkOrderType string `json:'WorkOrderType'`
Plant string `json:'Plant'`
Unit string `json:'Unit'`
LaborCost float64 `json:'LaborCost'`
MaterialCost float64 `json:'MaterialCost'`
ServiceCost float64 `json:'ServiceCost'`
}
result, DataMainEx, DataOrder, DataChart, DataTable, Temp, IDList := tk.M{}, []*DataValue{}, []*DataValue{}, []tk.M{}, []DataValue{}, []tk.M{}, []interface{}{}
c := ctx.Connection
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
groupBy := "Plant"
switch m.Scope {
case "Kingdom":
break
case "Plant":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Plant", m.Selected))
}
groupBy = "Unit"
break
case "Phase":
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Phase", m.Selected))
}
break
case "Unit":
query = append(query, dbox.Eq("Plant", m.SelectedPlant))
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Unit", m.Selected))
}
groupBy = "Unit"
break
default:
break
}
// Get DataMainEx
csr, e := c.NewQuery().
Where(query...).
Select(groupBy).
Aggr(dbox.AggrSum, "TotalLabourCost", "LaborCost").
Aggr(dbox.AggrSum, "TotalMaterialCost", "MaterialCost").
Aggr(dbox.AggrSum, "TotalServicesCost", "ServiceCost").
From(new(ValueEquation).TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if e != nil {
return nil, e
}
if csr != nil {
e = csr.Fetch(&DataMainEx, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range DataMainEx {
if i.Unit != "" {
i.ID = i.Unit
} else {
i.ID = i.Plant
}
}
csr, e = c.NewQuery().
Where(query...).Select("Id").
From(new(ValueEquation).TableName()).Cursor(nil)
if e != nil {
return nil, e
}
if csr != nil {
e = csr.Fetch(&Temp, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range Temp {
IDList = append(IDList, i.GetInt("id"))
}
query = []*dbox.Filter{}
query = append(query, dbox.In("VEId", IDList...))
// Get DataTable
csr, e = c.NewQuery().
Where(query...).
Select("DataSource", "WorkOrderType").
Aggr(dbox.AggrSum, "LaborCost", "LaborCost").
Aggr(dbox.AggrSum, "MaterialCost", "MaterialCost").
Aggr(dbox.AggrSum, "ServiceCost", "ServiceCost").
From(new(ValueEquationDetails).TableName()).Group("DataSource", "WorkOrderType").
Order("DataSource").
Cursor(nil)
//.........這裏部分代碼省略.........
示例15: GetSummaryData
func (m *HistoricalValueEquation) GetSummaryData(ctx *orm.DataContext, k *knot.WebContext) (interface{}, error) {
m.SetPayLoad(k)
type DataValue struct {
ID string
Plant string `json:'Plant'`
Unit string `json:'Unit'`
Revenue float64 `json:'Revenue'`
MaintenanceCost float64 `json:'MaintenanceCost'`
OperatingCost float64 `json:'OperatingCost'`
}
result, DataChart, DataDetail := tk.M{}, []DataValue{}, []*DataValue{}
c := ctx.Connection
ve := new(ValueEquation)
query := []*dbox.Filter{}
query = append(query, dbox.Gte("Dates", m.StartPeriod))
query = append(query, dbox.Lte("Dates", m.EndPeriod))
csr, e := c.NewQuery().
Where(query...).
Select("Plant").
Aggr(dbox.AggrSum, "Revenue", "Revenue").
Aggr(dbox.AggrSum, "MaintenanceCost", "MaintenanceCost").
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
From(ve.TableName()).Group("Plant").Order("Plant").Cursor(nil)
if e != nil {
return nil, e
}
if csr != nil {
e = csr.Fetch(&DataChart, 0, false)
}
if e != nil {
return nil, e
}
csr.Close()
result.Set("DataChart", DataChart)
groupBy := "Plant"
if m.Scope == "Plant" {
groupBy = "Unit"
if m.Selected != nil && len(m.Selected) > 0 {
query = append(query, dbox.In("Plant", m.Selected))
}
}
if m.Scope != "Unit" {
csr, e := c.NewQuery().
Where(query...).Select(groupBy).
Aggr(dbox.AggrSum, "Revenue", "Revenue").
Aggr(dbox.AggrSum, "MaintenanceCost", "MaintenanceCost").
Aggr(dbox.AggrSum, "OperatingCost", "OperatingCost").
From(ve.TableName()).Group(groupBy).Order(groupBy).Cursor(nil)
if csr != nil {
e = csr.Fetch(&DataDetail, 0, false)
}
csr.Close()
if e != nil {
return nil, e
}
for _, i := range DataDetail {
if i.Unit != "" {
i.ID = i.Unit
} else {
i.ID = i.Plant
}
}
}
result.Set("DataDetail", DataDetail)
return result, nil
}