示例#1
0
func (ctrl *ConfigController) SyncTime() {
	sess := ctrl.StartSession()
	state := sess.Get(utils.SessAuth)
	//state := utils.GetSolarMapItem(utils.SessAuth)
	fmt.Println("auth state=", state)

	if state != "ok" {
		utils.WriteDebugLog("Config: AUTH ERROR!")
		//ctrl.Redirect(URLAuth, 302)
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "data"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 3
		ctrl.TplNames = "cmd2.tpl"
	} else {
		fmt.Println("SyncTime")
		utils.WriteDebugLog("SyncTime: mac=%s", ctrl.GetString("mac"))

		curtime := time.Now().Unix()
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "synctime"
		ctrl.Data["command2"] = "time"
		ctrl.Data["value2"] = uint32(curtime)
		ctrl.TplNames = "cmd2.tpl"
	}
}
示例#2
0
func (ctrl *ConfigController) GetIVTTable() {
	sess := ctrl.StartSession()
	state := sess.Get(utils.SessAuth)

	//state := utils.GetSolarMapItem(utils.SessAuth)
	//state := "ok"
	//fmt.Println("auth state=", state)

	if state != "ok" {
		utils.WriteDebugLog("Config: AUTH ERROR!")
		//ctrl.Redirect(URLAuth, 302)
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "data"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 3
		ctrl.TplNames = "cmd2.tpl"
	} else {
		fmt.Println("Get Inverter Config File!")

		utils.WriteDebugLog("Get Inverter Table: %s", IVT_CONFIG_JSON_FILE)
		http.ServeFile(ctrl.Ctx.ResponseWriter, ctrl.Ctx.Request, IVT_CONFIG_JSON_FILE)

		ctrl.Data["value"] = 0
		ctrl.Data["command"] = "errcode"
		ctrl.TplNames = "cmd.tpl"
	}
}
示例#3
0
func (ctrl *DataController) Command() {
	sess := ctrl.StartSession()
	state := sess.Get(utils.SessAuth)

	//state := utils.GetSolarMapItem(utils.SessAuth)
	gwsn := ctrl.GetString("cmd")
	//fmt.Println("gwsn=", gwsn)
	if state != "ok" {
		utils.WriteDebugLog("Data: AUTH ERROR!")
		//ctrl.Redirect(URLAuth, 302)
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "data"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 3
		ctrl.TplNames = "cmd2.tpl"
	} else {
		fmt.Println("Command")
		//fmt.Println("content:=", models.SerialCommands(gwsn))

		utils.WriteDebugLog("/gw/cmd request")
		ctrl.Data["command"] = "commands"
		ctrl.Data["value"] = models.SerialCommands(gwsn)
		ctrl.TplNames = "cmd.tpl"
	}
}
示例#4
0
func DoUpdateDayTableItemBySQL(r *PvInverterDayData) error {
	tableName := getDayTableName(r.Day)

	s := fmt.Sprintf("UPDATE `%s`", tableName)
	s = fmt.Sprintf("%s SET ", s)
	s = fmt.Sprintf("%s `input_time` = '%v',", s, time.Now().Unix())
	s = fmt.Sprintf("%s `data_validate` = '%v',", s, r.DataValidate)
	s = fmt.Sprintf("%s `ac_active_power_total` = '%v',", s, r.AcActivePowerTotal)
	s = fmt.Sprintf("%s `energy_today` = '%v',", s, r.EnergyToday)
	s = fmt.Sprintf("%s `energy_total` = '%v',", s, r.EnergyTotal)
	s = fmt.Sprintf("%s `power_content` = '%v',", s, r.PowerContent)
	s = fmt.Sprintf("%s `nominal_hours` = '%v',", s, r.NominalHours)
	s = fmt.Sprintf("%s `today_hours` = '%v',", s, r.TodayHours)
	s = fmt.Sprintf("%s `avg_direct_power` = '%v',", s, r.AvgDirectPower)
	s = fmt.Sprintf("%s `avg_alternating_power` = '%v',", s, r.AvgAlternatingPower)
	s = fmt.Sprintf("%s `avg_efficiency` = '%v'", s, r.AvgEfficiency)
	s = fmt.Sprintf("%s WHERE (`ivt_id` = %d AND `day` = %v);", s, r.IvtId, r.Day)
	//fmt.Println("s=", s)

	o := orm.NewOrm()
	_, err := o.Raw(s).Exec()
	if err == nil {
		utils.WriteDebugLog("Update record(ivt_id=%d & day=%v) in table %s  ...... DONE", r.IvtId, r.Day, tableName)
	} else {
		utils.WriteErrorLog("Update record(ivt_id=%d & day=%v) in table %s  ...... ERROR", r.IvtId, r.Day, tableName)
	}

	return err
}
示例#5
0
func InsertRunDataTableItemBySQL(r *PvInverterRunData) {
	// use the r.SmplTime to generate the table
	t := time.Unix(r.SmplTime, 0)
	fmt.Println("t=%v", t)
	//fmt.Println("t.Unix=%v", t.Unix())

	// first, try to create the table
	CreateRunDataTableBySQL(t.Unix())

	// insert data to the table
	tableName := getRunDataTableName(t.Unix())

	s := fmt.Sprintf("INSERT INTO `%s`", tableName)
	s = fmt.Sprintf("%s (`ivt_id`, `batch_order`, `smpl_time`, `input_time`, `work_status`, `run_time_total`, `energy_total`, `energy_day`, `internal_temperature`, `vdc_pv1`, `idc_pv1`, `dcpower_pv1`, `vdc_pv2`, `idc_pv2`, `dcpower_pv2`, `vdc_pv3`, `idc_pv3`, `dcpower_pv3`, `vdc_pv4`, `idc_pv4`, `dcpower_pv4`, `pv1_resistor`, `pv2_resistor`, `pv3_resistor`, `pv4_resistor`, `aver_vdc_pv`, `idc_total`, `dcpower_total`, `vac_r`, `iac_r`, `acpower_r`, `fac_r`, `vac_s`, `iac_s`, `acpower_s`, `fac_s`, `vac_t`, `iac_t`, `acpower_t`, `fac_t`, `aver_vac`, `ac_active_power_total`, `iac_total`, `vac_balance`, `iac_balance`, `fgrid`, `efficiency`, `simu_kwh5_min`)", s)
	s = fmt.Sprintf("%s VALUES ", s)
	s = fmt.Sprintf("%s ('%v', '%v', '%v', '%v', '%s', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v');", s, r.IvtId, r.BatchOrder, r.SmplTime, time.Now().Unix(), r.WorkStatus, r.RunTimeTotal, r.EnergyTotal, r.EnergyDay, r.InternalTemperature, r.VdcPv1, r.IdcPv1, r.DcpowerPv1, r.VdcPv2, r.IdcPv2, r.DcpowerPv2, r.VdcPv3, r.IdcPv3, r.DcpowerPv3, r.VdcPv4, r.IdcPv4, r.DcpowerPv4, r.Pv1Resistor, r.Pv2Resistor, r.Pv3Resistor, r.Pv4Resistor, r.AverVdcPv, r.IdcTotal, r.DcpowerTotal, r.VacR, r.IacR, r.AcpowerR, r.FacR, r.VacS, r.IacS, r.AcpowerS, r.FacS, r.VacT, r.IacT, r.AcpowerT, r.FacT, r.AverVac, r.AcActivePowerTotal, r.IacTotal, r.VacBalance, r.IacBalance, r.Fgrid, r.Efficiency, r.SimuKwh5Min)
	//fmt.Println("s=", s)

	o := orm.NewOrm()
	res, err := o.Raw(s).Exec()
	if err == nil {
		num, _ := res.RowsAffected()
		fmt.Println("mysql row affected nums: ", num)
		utils.WriteDebugLog("Insert a record to %s table ...... DONE", tableName)
	} else {
		fmt.Printf("err=%v\n", err)
		fmt.Println("mysql insert data have an ERROR!")
		utils.WriteErrorLog("Insert a record to %s table ...... ERROR", tableName)
	}
}
示例#6
0
func handleAuthInitState(ctrl *AuthController, sess session.SessionStore) {
	// get sn
	sn := ctrl.GetString("sn")
	fmt.Println("sn=", sn)

	utils.WriteDebugLog("Auth: get sn")
	if len(sn) == 0 {
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "sn"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 1
		ctrl.TplNames = "cmd2.tpl"
	} else if len(sn) != 16 {
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "sn"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 2
		ctrl.TplNames = "cmd2.tpl"
	} else {
		DoSetSN(sn, sess)
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "sn"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 0

		ctrl.Data["command3"] = "ciphertext"
		ctrl.Data["value3"] = "12345678123456781234567812345678"
		ctrl.TplNames = "cmd3.tpl"
	}
}
示例#7
0
func handleAuthSNState(ctrl *AuthController, sess session.SessionStore) {
	// get cipher
	cipher := ctrl.GetString("cipher")
	fmt.Println("cipher=", cipher)

	utils.WriteDebugLog("Auth: get cipher")
	if len(cipher) == 0 {
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "cipher"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 1
		ctrl.TplNames = "cmd2.tpl"
	} else if len(cipher) != 32 {
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "cipher"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 2
		ctrl.TplNames = "cmd2.tpl"
	} else {
		DoSetCipher(cipher, sess)
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "cipher"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 0

		ctrl.TplNames = "cmd2.tpl"
	}
}
示例#8
0
func (ctrl *DataController) Post() {
	sess := ctrl.StartSession()
	state := sess.Get(utils.SessAuth)

	//state := utils.GetSolarMapItem(utils.SessAuth)
	utils.WriteDebugLog("/gw/data POST request")
	if state != "ok" {
		utils.WriteDebugLog("Data: AUTH ERROR!")
		//ctrl.Redirect(URLAuth, 302)
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "data"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 3
		ctrl.TplNames = "cmd2.tpl"
	} else {
		handleDataRequest(ctrl)
	}
}
示例#9
0
func handleAuthOKState(ctrl *AuthController, sess session.SessionStore) {
	ctrl.Data["command1"] = "cmd"
	ctrl.Data["value1"] = "cipher"
	ctrl.Data["command2"] = "errcode"
	ctrl.Data["value2"] = 0

	ctrl.TplNames = "cmd2.tpl"
	fmt.Println("Auth OK!")
	utils.WriteDebugLog("AUTH already OK!")
}
示例#10
0
func DoAuth(sess session.SessionStore) {
	if utils.IsPassedAuth() {
		sess.Set(utils.SessAuth, "ok")
		utils.UpdateSolarMapItem(utils.SessAuth, "ok")
		fmt.Println("AUTH OK!")
		utils.WriteDebugLog("AUTH OK!")
	} else {
		sess.Set(utils.SessAuth, "none")
		utils.UpdateSolarMapItem(utils.SessAuth, "none")
	}
}
示例#11
0
func (ctrl *ConfigController) Post() {
	fmt.Println("config controller post method")

	sess := ctrl.StartSession()
	state := sess.Get(utils.SessAuth)
	//state := utils.GetSolarMapItem(utils.SessAuth)
	//fmt.Println("auth state=", state)

	if state != "ok" {
		utils.WriteDebugLog("Config: AUTH ERROR!")
		//ctrl.Redirect(URLAuth, 302)
		ctrl.Data["command1"] = "cmd"
		ctrl.Data["value1"] = "data"
		ctrl.Data["command2"] = "errcode"
		ctrl.Data["value2"] = 3
		ctrl.TplNames = "cmd2.tpl"
	} else {
		handleConfigRequest(ctrl)
	}
}
示例#12
0
func DoInsertDayTableRecordBySQL(r *PvInverterDayData) {
	tableName := getDayTableName(r.Day)

	s := fmt.Sprintf("INSERT INTO `%s`", tableName)
	s = fmt.Sprintf("%s (`ivt_id`, `input_time`, `day`, `data_validate`, `ac_active_power_total`, `energy_today`, `energy_total`, `power_content`, `nominal_hours`, `today_hours`, `avg_direct_power`, `avg_alternating_power`, `avg_efficiency`)", s)
	s = fmt.Sprintf("%s VALUES ", s)
	s = fmt.Sprintf("%s ('%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v', '%v');", s, r.IvtId, time.Now().Unix(), r.Day, r.DataValidate, r.AcActivePowerTotal, r.EnergyToday, r.EnergyTotal, r.PowerContent, r.NominalHours, r.TodayHours, r.AvgDirectPower, r.AvgAlternatingPower, r.AvgEfficiency)
	//fmt.Println("s=", s)

	// Run the SQL
	o := orm.NewOrm()
	res, err := o.Raw(s).Exec()
	if err == nil {
		num, _ := res.RowsAffected()
		fmt.Println("mysql row affected nums: ", num)
		utils.WriteDebugLog("Insert a record to %s table ...... DONE", tableName)
	} else {
		fmt.Printf("err=%v\n", err)
		fmt.Println("mysql insert data have an ERROR!")
		utils.WriteErrorLog("Insert a record to %s table ...... ERROR", tableName)
	}
}
示例#13
0
func CreateDayTableBySQL(t int64) {
	year := time.Unix(t, 0).Year()
	//month := time.Unix(t, 0).Month()
	tableName := getDayTableName(t)

	s := "CREATE TABLE IF NOT EXISTS"
	s = fmt.Sprintf("%s `%s`", s, tableName)
	s = fmt.Sprintf("%s ( `id` bigint AUTO_INCREMENT NOT NULL PRIMARY KEY,", s)
	s = fmt.Sprintf("%s `ivt_id` int(11) NOT NULL DEFAULT '0' COMMENT '逆变器ID',", s)
	s = fmt.Sprintf("%s `input_time` int(10) DEFAULT NULL DEFAULT '0' COMMENT '最后更新时间',", s)
	s = fmt.Sprintf("%s `day` int(10) NOT NULL DEFAULT '0' COMMENT '数据日期',", s)
	s = fmt.Sprintf("%s `data_validate` smallint(1) NOT NULL DEFAULT '0' COMMENT '数据完整性验算',", s)
	s = fmt.Sprintf("%s `ac_active_power_total` float(8,2) NOT NULL DEFAULT '0.00' COMMENT '实时总功率',", s)
	s = fmt.Sprintf("%s `energy_today` float(8,2) NOT NULL DEFAULT '0.00' COMMENT '当日实时总发电量',", s)
	s = fmt.Sprintf("%s `energy_total` double(10,2) NOT NULL DEFAULT '0.00' COMMENT '总发电量',", s)
	s = fmt.Sprintf("%s `power_content` text NOT NULL DEFAULT '' COMMENT '当日历史功率',", s)
	s = fmt.Sprintf("%s `nominal_hours` int(11) NOT NULL DEFAULT '0' COMMENT '名义发电小时数',", s)
	s = fmt.Sprintf("%s `today_hours` float(5,3) NOT NULL DEFAULT '0.000' COMMENT '当日有效发电小时数',", s)
	s = fmt.Sprintf("%s `avg_direct_power` float(8,1) NOT NULL DEFAULT '0.0' COMMENT '当日有效直流平均功率',", s)
	s = fmt.Sprintf("%s `avg_alternating_power` float(8,1) NOT NULL DEFAULT '0.0' COMMENT '当日截止到目前的有效交流平均功率',", s)
	s = fmt.Sprintf("%s `avg_efficiency` float(4,3) NOT NULL DEFAULT '0.000' COMMENT '当日截止到目前的逆变器平均效率')", s)
	s = fmt.Sprintf("%s ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='%d年所有逆变器每日数据统计表';", s, year)
	//fmt.Println("s=", s)

	o := orm.NewOrm()
	_, err := o.Raw(s).Exec()
	if err == nil {
		fmt.Println("Create %s table SUCCESS!", tableName)
		utils.WriteDebugLog("Create %s table ...... DONE", tableName)
	} else {
		fmt.Printf("Create err=%v\n", err)
		fmt.Println("Create table ERROR!")
		utils.WriteErrorLog("Create %s table ...... ERROR", tableName)
	}

}
示例#14
0
func handleConfigRequest(ctrl *ConfigController) {
	stylename := ctrl.GetString(CMD_GET_STYLE_FILE)
	fwname := ctrl.GetString(CMD_GET_FW_FILE)
	filename := ctrl.GetString(CMD_GET_FILE)

	gwsn := ctrl.GetString(CMD_REPORT_GWSN)
	fwver := ctrl.GetString(CMD_REPORT_FWVER)
	ipaddr := ctrl.GetString(CMD_REPORT_IPADDR)

	ctrl.Data["value"] = 0
	ctrl.Data["command"] = "errcode"

	// first, handle the gwsn & fwver parameters
	// these two parameters MUST come same time
	if gwsn != "" && (fwver != "" || ipaddr != "") {
		handleConfigGWInfo(gwsn, fwver, ipaddr)
	} else if gwsn == "" && fwver == "" && ipaddr == "" {
		// do nothing
	} else {
		ctrl.Data["value"] = 2
	}

	// second, handle style name
	if len(stylename) != 0 {
		if utils.IsFileExist(FILE_STYLE_PATH + stylename + FILE_JSON) {
			http.ServeFile(ctrl.Ctx.ResponseWriter, ctrl.Ctx.Request, FILE_STYLE_PATH+stylename+FILE_JSON)
			utils.WriteDebugLog("Send back the device style file: %s", FILE_STYLE_PATH+stylename+FILE_JSON)
		} else {
			ctrl.Data["value"] = 4
		}
	}

	// third , handle fireware name
	if len(fwname) != 0 {
		if utils.IsFileExist(FILE_FW_PATH + fwname) {
			http.ServeFile(ctrl.Ctx.ResponseWriter, ctrl.Ctx.Request, FILE_FW_PATH+fwname)
			utils.WriteDebugLog("Send back the firmware image: %s", FILE_FW_PATH+fwname)
		} else {
			ctrl.Data["value"] = 4
		}
	}

	// last, handle file name
	if len(filename) != 0 {
		if utils.IsFileExist(FILE_DEF_PATH + filename) {
			http.ServeFile(ctrl.Ctx.ResponseWriter, ctrl.Ctx.Request, FILE_DEF_PATH+filename)
			utils.WriteDebugLog("Send back the file: %s", FILE_DEF_PATH+filename)
		} else {
			ctrl.Data["value"] = 4
		}
	}

	ctrl.TplNames = "cmd.tpl"

	// fmt.Printf("stylefile=%v, firmware=%v, file=%v\n", stylename, fwname, filename)

	// if len(stylename) == 0 {
	// 	ctrl.Data["value"] = 1
	// 	ctrl.Data["command"] = "errcode"
	// 	ctrl.TplNames = "cmd.tpl"
	// } else if utils.IsFileExist(FILE_STYLE_PATH + stylename + FILE_JSON) {
	// 	// find the file
	// 	http.ServeFile(ctrl.Ctx.ResponseWriter, ctrl.Ctx.Request, FILE_STYLE_PATH+stylename+FILE_JSON)
	// 	utils.WriteDebugLog("Send back the device style file: %s", FILE_STYLE_PATH+stylename+FILE_JSON)
	// 	//ctrl.Data["value"] = 0
	// } else {
	// 	ctrl.Data["value"] = 2
	// 	ctrl.Data["command"] = "errcode"
	// 	ctrl.TplNames = "cmd.tpl"
	// }
}
示例#15
0
func handleDataRequest(ctrl *DataController) {
	data := ctrl.GetString("data")

	// send back the json file
	ctrl.Data["command1"] = "cmd"
	ctrl.Data["value1"] = "data"
	ctrl.Data["command2"] = "errcode"
	ctrl.Data["value2"] = 2
	ctrl.TplNames = "cmd2.tpl"

	if data != "" {
		//var s []byte = []byte(sData)
		var s []byte = []byte(data)

		fmt.Println("data=", data)
		utils.WriteDebugLog("Handle Data: data=%v", data)
		stylecode := utils.PeekStyleCode(s)
		fmt.Printf("stylecode=%v\n", stylecode)
		fname := FILE_STYLE_PATH + "SD" + stylecode[1] + stylecode[2] + ".json"
		_, err := ioutil.ReadFile(fname)
		if err != nil {
			fmt.Println("ReadJSONFile:", err.Error())
		} else {
			fmt.Println("ReadJSONFile SUCCESS!")
		}

		item := models.NewPvInverterRunData()
		dataMap := utils.HandleSDData(fname, s)
		genIvtRunDataDBItem(item, fname, dataMap)

		// get the inverter sn
		sn := getInverterSN(dataMap)
		if len(sn) != 0 && sn[0] != 0 {
			item.IvtId, _ = models.GetIvtIdByIvtSN(sn)
			//fmt.Println("item.IvtId=", item.IvtId)
		} else {
			gw := strings.Split(getGWSN(dataMap), ":")
			var gwsn string = ""
			for _, v := range gw {
				gwsn += v
			}
			addr := fmt.Sprintf("%v", getDAddr(dataMap))
			//fmt.Printf("gwsn=%v, addr=%s\n", gwsn, addr)
			utils.WriteDebugLog("Can't get ivt_sn, use gw_sn & ivt_address")
			utils.WriteDebugLog("        gwsn=%s, addr=%s", gwsn, addr)
			item.IvtId, _ = models.GetIvtIdByGWInfo(gwsn, addr)
		}
		utils.WriteDebugLog("Parse Data: ivt_id=%v, batch_order=%v, smpl_time=%v, ", item.IvtId, item.BatchOrder, item.SmplTime)
		utils.WriteDebugLog("            input_time=%v, work_status=%v, run_time_total=%v, ", item.InputTime, item.WorkStatus, item.RunTimeTotal)
		utils.WriteDebugLog("            energy_total=%v, energy_day=%v, internal_temperature=%v, ", item.EnergyTotal, item.EnergyDay, item.InternalTemperature)
		utils.WriteDebugLog("            vdc_pv1=%v, idc_pv1=%v, dcpower_pv1=%v, ", item.VdcPv1, item.IdcPv1, item.DcpowerPv1)
		utils.WriteDebugLog("            vdc_pv2=%v, idc_pv2=%v, dcpower_pv2=%v, ", item.VdcPv2, item.IdcPv2, item.DcpowerPv2)
		utils.WriteDebugLog("            vdc_pv3=%v, idc_pv3=%v, dcpower_pv3=%v, ", item.VdcPv3, item.IdcPv3, item.DcpowerPv3)
		utils.WriteDebugLog("            vdc_pv4=%v, idc_pv4=%v, dcpower_pv4=%v, ", item.VdcPv4, item.IdcPv4, item.DcpowerPv4)
		utils.WriteDebugLog("            pv1_resistor=%v, pv2_resistor=%v, pv3_resistor=%v, pv4_resistor=%v, ", item.Pv1Resistor, item.Pv2Resistor, item.Pv3Resistor, item.Pv4Resistor)
		utils.WriteDebugLog("            aver_vdc_pv=%v, idc_total=%v, dcpower_total=%v, ", item.AverVdcPv, item.IdcTotal, item.DcpowerTotal)
		utils.WriteDebugLog("            vac_r=%v, iac_r=%v, acpower_r=%v, fac_r=%v ", item.VacR, item.IacR, item.AcpowerR, item.FacR)
		utils.WriteDebugLog("            vac_s=%v, iac_s=%v, acpower_s=%v, fac_s=%v ", item.VacS, item.IacS, item.AcpowerS, item.FacS)
		utils.WriteDebugLog("            vac_t=%v, iac_t=%v, acpower_t=%v, fac_t=%v ", item.VacT, item.IacT, item.AcpowerT, item.FacT)
		utils.WriteDebugLog("            aver_vac=%v, ac_active_power_total=%v, iac_total=%v, ", item.AverVac, item.AcActivePowerTotal, item.IacTotal)
		utils.WriteDebugLog("            vac_balance=%v, iac_balance=%v, ", item.VacBalance, item.IacBalance)
		utils.WriteDebugLog("            fgrid=%v, efficiency=%v, simu_kwh5_min=%v", item.Fgrid, item.Efficiency, item.SimuKwh5Min)

		// calculate the day data & update it transfer to Solarzoom
		// so comment the code
		// dayRecord := models.NewPvInverterDayData()
		// dayRecord.IvtId = item.IvtId
		// dayRecord.Day = models.CalcDayTableDayItem(item.SmplTime)
		// dayRecord.AcActivePowerTotal = item.AcActivePowerTotal
		// dayRecord.EnergyTotal = item.EnergyTotal
		// dayRecord.EnergyToday = item.EnergyDay
		// dayRecord.PowerContent, _ = models.GetPowerContentInDayTable(dayRecord)
		// //fmt.Println("1 --- dayRecord.PowerContent=", dayRecord.PowerContent)

		// dayRecord.PowerContent = fmt.Sprintf("%s#%v:%v:%v", dayRecord.PowerContent, item.BatchOrder, item.SmplTime, item.DcpowerTotal)

		//fmt.Println("2 --- dayRecord.PowerContent=", dayRecord.PowerContent)
		// careate the new table
		// item.TableName()
		//models.CreateDayTableBySQL()
		//models.InsertDayTableItemBySQL()
		models.InsertRunDataTableItemBySQL(item)
		// models.UpdateDayTableRecordBySQL(dayRecord)

		//item.WorkStatus = "Error"
		// check the workstatus
		if item.WorkStatus == STR_FAULT {
			// write the fault table
			fault := models.NewPvInverterFaultData()
			fault.IvtId = item.IvtId
			fault.StartTime = item.SmplTime
			fault.FaultMessage = getErrorMessage(item, fname, dataMap)

			models.InsertFaultTableItemBySQL(fault)
		}

		ctrl.Data["value2"] = 0
	}
}
示例#16
0
func CreateRunDataTableBySQL(t int64) {
	year := time.Unix(t, 0).Year()
	month := time.Unix(t, 0).Month()

	tableName := getRunDataTableName(t)
	s := "CREATE TABLE IF NOT EXISTS"
	s = fmt.Sprintf("%s `%s` (", s, tableName)
	s = fmt.Sprintf("%s `id` bigint AUTO_INCREMENT NOT NULL PRIMARY KEY,", s)
	s = fmt.Sprintf("%s `ivt_id` int(11) NOT NULL DEFAULT '0' COMMENT '逆变器ID',", s)
	s = fmt.Sprintf("%s `batch_order` int(4) NOT NULL DEFAULT '0' COMMENT '数据采集序号',", s)
	s = fmt.Sprintf("%s `smpl_time` int(10) NOT NULL DEFAULT '0' COMMENT '数据采集时间',", s)
	s = fmt.Sprintf("%s `input_time` int(10) NOT NULL DEFAULT '0' COMMENT '数据写入时间',", s)
	s = fmt.Sprintf("%s `work_status` varchar(32) NOT NULL DEFAULT '' COMMENT '当前最新运行状态',", s)
	s = fmt.Sprintf("%s `run_time_total` double(8,2) NOT NULL DEFAULT '0' COMMENT '总运行时间',", s)
	s = fmt.Sprintf("%s `energy_total` double(10,2) NOT NULL DEFAULT '0' COMMENT '总发电量',", s)
	s = fmt.Sprintf("%s `energy_day` float(8,2) NOT NULL DEFAULT '0' COMMENT '今日总发电量',", s)
	s = fmt.Sprintf("%s `internal_temperature` float(5, 2) NOT NULL DEFAULT '0' COMMENT '逆变器内部温度',", s)
	s = fmt.Sprintf("%s `vdc_pv1` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV1直流电压',", s)
	s = fmt.Sprintf("%s `idc_pv1` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV1直流电流',", s)
	s = fmt.Sprintf("%s `dcpower_pv1` float(8, 1) NOT NULL DEFAULT '0' COMMENT 'PV1直流功率',", s)
	s = fmt.Sprintf("%s `vdc_pv2` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV2直流电压',", s)
	s = fmt.Sprintf("%s `idc_pv2` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV2直流电流',", s)
	s = fmt.Sprintf("%s `dcpower_pv2` float(8, 1) NOT NULL DEFAULT '0' COMMENT 'PV2直流功率',", s)
	s = fmt.Sprintf("%s `vdc_pv3` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV3直流电压',", s)
	s = fmt.Sprintf("%s `idc_pv3` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV3直流电流',", s)
	s = fmt.Sprintf("%s `dcpower_pv3` float(8, 1) NOT NULL DEFAULT '0' COMMENT 'PV3直流功率',", s)
	s = fmt.Sprintf("%s `vdc_pv4` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV4直流电压',", s)
	s = fmt.Sprintf("%s `idc_pv4` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV4直流电流',", s)
	s = fmt.Sprintf("%s `dcpower_pv4` float(8, 1) NOT NULL DEFAULT '0' COMMENT 'PV4直流功率',", s)
	s = fmt.Sprintf("%s `pv1_resistor` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV1正对地绝缘阻抗',", s)
	s = fmt.Sprintf("%s `pv2_resistor` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV2正对地绝缘阻抗',", s)
	s = fmt.Sprintf("%s `pv3_resistor` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV3正对地绝缘阻抗',", s)
	s = fmt.Sprintf("%s `pv4_resistor` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'PV4正对地绝缘阻抗',", s)
	s = fmt.Sprintf("%s `aver_vdc_pv` float(4, 1) NOT NULL DEFAULT '0' COMMENT '平均直流电压',", s)
	s = fmt.Sprintf("%s `idc_total` float(4, 1) NOT NULL DEFAULT '0' COMMENT '总直流电流',", s)
	s = fmt.Sprintf("%s `dcpower_total` float(9, 1) NOT NULL DEFAULT '0' COMMENT '总直流功率',", s)
	s = fmt.Sprintf("%s `vac_r` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'R相电压',", s)
	s = fmt.Sprintf("%s `iac_r` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'R相电流',", s)
	s = fmt.Sprintf("%s `acpower_r` float(8, 1) NOT NULL DEFAULT '0' COMMENT 'R相输出功率',", s)
	s = fmt.Sprintf("%s `fac_r` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'R相频率',", s)
	s = fmt.Sprintf("%s `vac_s` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'S相电压',", s)
	s = fmt.Sprintf("%s `iac_s` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'S相电流',", s)
	s = fmt.Sprintf("%s `acpower_s` float(8, 1) NOT NULL DEFAULT '0' COMMENT 'S相输出功率',", s)
	s = fmt.Sprintf("%s `fac_s` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'S相频率',", s)
	s = fmt.Sprintf("%s `vac_t` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'T相电压',", s)
	s = fmt.Sprintf("%s `iac_t` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'T相电流',", s)
	s = fmt.Sprintf("%s `acpower_t` float(8, 1) NOT NULL DEFAULT '0' COMMENT 'T相输出功率',", s)
	s = fmt.Sprintf("%s `fac_t` float(5, 2) NOT NULL DEFAULT '0' COMMENT 'T相频率',", s)
	s = fmt.Sprintf("%s `aver_vac` float(4, 1) NOT NULL DEFAULT '0' COMMENT '平均交流电压',", s)
	s = fmt.Sprintf("%s `ac_active_power_total` float(8, 2) NOT NULL DEFAULT '0' COMMENT '总有功功率',", s)
	s = fmt.Sprintf("%s `iac_total` float(4, 1) NOT NULL DEFAULT '0' COMMENT '总交流电流',", s)
	s = fmt.Sprintf("%s `vac_balance` float(5, 2) NOT NULL DEFAULT '0' COMMENT '交流电压三相平衡度',", s)
	s = fmt.Sprintf("%s `iac_balance` float(5, 2) NOT NULL DEFAULT '0' COMMENT '交流直流三相平衡度',", s)
	s = fmt.Sprintf("%s `fgrid` float(5, 2) NOT NULL DEFAULT '0' COMMENT '电网频率',", s)
	s = fmt.Sprintf("%s `efficiency` float(7, 3) NOT NULL DEFAULT '0' COMMENT '逆变器效率',", s)
	s = fmt.Sprintf("%s `simu_kwh5_min` float(7, 2) NOT NULL DEFAULT '0' COMMENT '五分钟模拟发电量'", s)
	s = fmt.Sprintf("%s ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='%d年%02d月份所有逆变器实时运行数据表';", s, year, month)

	//fmt.Println("s=", s)
	o := orm.NewOrm()
	_, err := o.Raw(s).Exec()
	if err == nil {
		utils.WriteDebugLog("Create %s table ...... DONE", tableName)
		fmt.Println("Create %s table SUCCESS!", tableName)
	} else {
		fmt.Printf("Create err=%v\n", err)
		fmt.Println("Create table ERROR!")
		utils.WriteErrorLog("Create %s table ...... ERROR", tableName)
	}
}