コード例 #1
0
ファイル: dashboard.go プロジェクト: yanda15/powerplant
func (c *DashboardController) GetPowerVsFuelConsumtion(k *knot.WebContext) interface{} {
	//c.LoadBase(k)
	k.Config.OutputType = knot.OutputJson

	d := struct {
		StartDate string
		EndDate   string
		Period    int
		Plant     []string
	}{}

	e := k.GetPayload(&d)

	r := new(tk.Result)
	r.Run(func(in interface{}) (interface{}, error) {

		var (
			filter []*dbox.Filter
		)

		selectedPeriod := d.Period
		filter = append(filter, dbox.Eq("Year", selectedPeriod))

		if len(d.Plant) > 0 {
			filter = append(filter, dbox.Eq("Plant", d.Plant[0]))
		}

		result := make([]tk.M, 0)

		cursor, e := c.DB().Connection.NewQuery().
			Select("Plant as _id").
			From("ValueEquation_Dashboard").
			Where(filter...).
			Group("Plant").
			Aggr(dbox.AggrSum, "UpdatedFuelConsumption", "FuelConsumtion").
			Aggr(dbox.AggrSum, "NetGeneration", "Power").
			Order("_id").
			Cursor(nil)

		defer cursor.Close()

		e = cursor.Fetch(&result, 0, true)

		e = c.CheckNotError(e)

		return result, e
	}, nil)

	return ResultInfo(r, e)
}
コード例 #2
0
ファイル: dashboard.go プロジェクト: yanda15/powerplant
func (c *DashboardController) GetNumberOfWorkOrder(k *knot.WebContext) interface{} {
	k.Config.OutputType = knot.OutputJson

	var e error
	r := new(tk.Result)

	d := struct {
		EndDate   string
		Plant     []string
		StartDate string
	}{}

	e = k.GetPayload(&d)

	r.Run(func(in interface{}) (interface{}, error) {

		filter := ""
		sintax := ""

		if len(d.Plant) > 0 {
			filter = d.Plant[0]
		}

		result := make([]tk.M, 0)

		if filter == "" {
			sintax = "select dbo.ValueEquation_Dashboard.Year as period, dbo.VEDTop10.WorkOrderType, count(*) as count, sum(dbo.VEDTop10.MaintenanceCost) as cost from dbo.ValueEquation_Dashboard inner join dbo.VEDTop10 on dbo.ValueEquation_Dashboard.Id = dbo.VEDTop10.VEId group by dbo.ValueEquation_Dashboard.Year, dbo.VEDTop10.WorkOrderType order by period asc, cost asc"
		} else {
			sintax = "select dbo.ValueEquation_Dashboard.Year as period, dbo.VEDTop10.WorkOrderType, count(*) as count, sum(dbo.VEDTop10.MaintenanceCost) as cost from dbo.ValueEquation_Dashboard inner join dbo.VEDTop10 on dbo.ValueEquation_Dashboard.Id = dbo.VEDTop10.VEId where dbo.ValueEquation_Dashboard.Plant = '" + filter + "' group by dbo.ValueEquation_Dashboard.Year, dbo.VEDTop10.WorkOrderType order by period asc, cost asc"
		}

		cursor, e := c.DB().Connection.NewQuery().
			Command("freequery", tk.M{}.
				Set("syntax", sintax)).
			Cursor(nil)

		_ = filter
		defer cursor.Close()
		e = cursor.Fetch(&result, 0, true)

		e = c.CheckNotError(e)

		return result, e
	}, nil)

	return ResultInfo(r, e)
}
コード例 #3
0
ファイル: dashboard.go プロジェクト: yanda15/powerplant
func (c *DashboardController) GetNumberOfTurbines(k *knot.WebContext) interface{} {
	k.Config.OutputType = knot.OutputJson

	var e error
	r := new(tk.Result)

	d := struct {
		StartDate string
		EndDate   string
		Plant     []string
	}{}

	e = k.GetPayload(&d)

	r.Run(func(in interface{}) (interface{}, error) {
		var filter []*dbox.Filter

		selectedPeriod := time.Now().Year() - 1

		filter = append(filter, dbox.Eq("Year", selectedPeriod))
		filter = append(filter, dbox.Ne("UnitType", ""))

		if len(d.Plant) != 0 {
			filter = append(filter, dbox.Eq("Plant", d.Plant[0]))
		}

		result := make([]tk.M, 0)

		cursor, _ := c.DB().Connection.NewQuery().
			Select("UnitType as _id").
			From("ValueEquation_Dashboard").
			Where(filter...).
			Group("UnitType").
			Aggr(dbox.AggrSum, 1, "count").
			Order("count").
			Cursor(nil)

		defer cursor.Close()
		e = cursor.Fetch(&result, 0, true)

		e = c.CheckNotError(e)
		return result, e
	}, nil)

	return ResultInfo(r, e)
}
コード例 #4
0
ファイル: databrowser.go プロジェクト: yanda15/powerplant
func (this *DataBrowserController) SaveExcel(k *knot.WebContext) interface{} {
	k.Config.OutputType = knot.OutputJson

	d := DataBrowserInput{}

	_ = k.GetPayload(&d)

	var (
		DisplaySumList []SumList
	)

	r := new(tk.Result)

	r.Run(func(in interface{}) (interface{}, error) {

		params, e := getDataBrowser(d)

		// ret.Set("Datas", datas)

		// get total and summary

		total := 0          //k.Session(d.Hypoid+"Total", nil)
		summary := []tk.M{} //k.Session(d.Hypoid+"Summary", nil)

		// if total == nil || summary == nil || len(fieldsdouble) > 0 {
		summaryStr := " count(*) as Total"

		for _, val := range d.Fieldsdouble {
			strSum := ",(Select CAST((Sum(" + val + ")) as float)) as " + val + "sum"
			strAvg := ",(Select CAST((Avg(" + val + ")) as float)) as " + val + "avg"

			summaryStr += strSum
			summaryStr += strAvg
		}

		params.Set("@Summary", summaryStr)

		script := getSQLScript(SQLScript+"/databrowser_h3_summary.sql", params)
		// tk.Printf("---\n%#v \n----\n", script)
		cursorTotal, e := this.DB().Connection.NewQuery().
			Command("freequery", tk.M{}.Set("syntax", script)).
			Cursor(nil)

		defer cursorTotal.Close()

		resSum := []tk.M{}

		e = cursorTotal.Fetch(&resSum, 0, true)

		if e != nil && e.Error() == "No more data to fetched!" {
			e = nil
		}

		if len(resSum) > 0 {
			tmp := resSum[0]
			total = tmp.GetInt("total")
			tmpSummary := tk.M{}

			for _, val := range d.Fieldsdouble {
				tmpSummary.Set(val+"avg", tmp.GetFloat64(strings.ToLower(val+"avg")))
				tmpSummary.Set(val+"sum", tmp.GetFloat64(strings.ToLower(val+"sum")))
			}

			summary = []tk.M{tmpSummary}
		}

		params.Set("@Offset", 0)
		params.Set("@Limit", total)

		script = getSQLScript(SQLScript+"/databrowser_h3.sql", params)

		// tk.Printf("---\n%#v \n----\n", script)
		cursor, e := this.DB().Connection.NewQuery().
			Command("freequery", tk.M{}.Set("syntax", script)).
			Cursor(nil)

		defer cursor.Close()

		// datas := []SPDataBrowser{}
		datas := make([]tk.M, 0)

		e = cursor.Fetch(&datas, 0, true)

		if e != nil && e.Error() == "No more data to fetched!" {
			e = nil
		}

		DisplayTypeCount := d.DisplayTypeCount
		DisplaySumList = []SumList{}
		for i := 0; i < DisplayTypeCount; i++ {
			sumData := SumList{}
			sumData.field = d.DisplayTypeList[i].Get("field").(string)
			sumData.tipe = d.DisplayTypeList[i].Get("type").(string)
			DisplaySumList = append(DisplaySumList, sumData)
		}

		excelFile, e := this.genExcelFile(d.HeaderList, d.Fields, datas, summary, DisplaySumList)
		return "../" + excelFile, e
	}, nil)

	tk.Printf("%#v \n", r)

	return r
}
コード例 #5
0
ファイル: databrowser.go プロジェクト: yanda15/powerplant
func (this *DataBrowserController) GetFilter(k *knot.WebContext) interface{} {
	k.Config.OutputType = knot.OutputJson

	var e error

	r := new(tk.Result)
	d := DataBrowserInput{}
	f := tk.M{}
	ret := tk.M{}

	_ = k.GetForms(&f)
	_ = k.GetPayload(&d)

	// tk.Printf("%#v \n", f)

	r.Run(func(in interface{}) (interface{}, error) {

		activeField := f.GetString("active_field")

		if activeField != "" {
			params, err := getDataBrowser(d)
			// get datas
			params.Set("@GROUP", activeField)

			script := getSQLScript(SQLScript+"/databrowser_h3_filter.sql", params)

			// tk.Printf("---\n%#v \n----\n", script)
			cursor, err := this.DB().Connection.NewQuery().
				Command("freequery", tk.M{}.Set("syntax", script)).
				Cursor(nil)

			defer cursor.Close()

			// datas := []SPDataBrowser{}
			tmpDatas := []tk.M{}
			datas := []tk.M{}

			err = cursor.Fetch(&tmpDatas, 0, true)

			if e != nil && e.Error() == "No more data to fetched!" {
				e = nil
			}

			if len(tmpDatas) > 0 {
				for _, val := range tmpDatas {
					tmp := tk.M{}
					tmp.Set("_id", val.Get(strings.ToLower(activeField)))
					tmp.Set(activeField, val.Get(strings.ToLower(activeField)))

					datas = append(datas, tmp)
				}
			}

			ret.Set("Data", datas)

			e = err
		}

		return ret, e
	}, nil)

	return r
}
コード例 #6
0
ファイル: databrowser.go プロジェクト: yanda15/powerplant
func (this *DataBrowserController) GetGridDb(k *knot.WebContext) interface{} {
	k.Config.OutputType = knot.OutputJson

	r := new(tk.Result)
	d := DataBrowserInput{}
	_ = k.GetPayload(&d)
	ret := tk.M{}

	r.Run(func(in interface{}) (interface{}, error) {

		params, e := getDataBrowser(d)

		// get datas

		script := getSQLScript(SQLScript+"/databrowser_h3.sql", params)

		// tk.Printf("---\n%#v \n----\n", script)
		datas := []SPDataBrowser{}
		cursor, e := this.DB().Connection.NewQuery().
			Command("freequery", tk.M{}.Set("syntax", script)).
			Cursor(nil)
		e = cursor.Fetch(&datas, 0, true)

		cursor.Close()

		if e != nil && e.Error() == "No more data to fetched!" {
			e = nil
		}

		ret.Set("Datas", datas)

		// get total and summary

		total := k.Session(d.Hypoid+"Total", nil)
		summary := k.Session(d.Hypoid+"Summary", nil)

		// if total == nil || summary == nil || len(fieldsdouble) > 0 {
		summaryStr := " count(*) as Total"

		for _, val := range d.Fieldsdouble {
			strSum := ",(Select CAST((Sum(" + val + ")) as float)) as " + val + "sum"
			strAvg := ",(Select CAST((Avg(" + val + ")) as float)) as " + val + "avg"

			summaryStr += strSum
			summaryStr += strAvg
		}

		params.Set("@Summary", summaryStr)

		script = getSQLScript(SQLScript+"/databrowser_h3_summary.sql", params)
		// tk.Printf("---\n%#v \n----\n", script)
		resSum := []tk.M{}
		cursorTotal, e := this.DB().Connection.NewQuery().
			Command("freequery", tk.M{}.Set("syntax", script)).
			Cursor(nil)
		e = cursorTotal.Fetch(&resSum, 0, true)
		cursorTotal.Close()

		if e != nil && e.Error() == "No more data to fetched!" {
			e = nil
		}

		if len(resSum) > 0 {
			tmp := resSum[0]
			total = tmp.GetInt("total")
			tmpSummary := tk.M{}

			for _, val := range d.Fieldsdouble {
				tmpSummary.Set(val+"avg", tmp.GetFloat64(strings.ToLower(val+"avg")))
				tmpSummary.Set(val+"sum", tmp.GetFloat64(strings.ToLower(val+"sum")))
			}

			summary = []tk.M{tmpSummary}

			/*k.SetSession(d.Hypoid+"Total", total)
			k.SetSession(d.Hypoid+"Summary", summary)*/

			ret.Set("Total", total)
			ret.Set("Summary", summary)
		}
		/*} else {
			ret.Set("Total", total)
			ret.Set("Summary", summary)
		}*/
		return ret, e
	}, nil)

	return r
}