Skip to content

Commit

Permalink
Automated lint fixes [dependabot skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Bot committed Jul 11, 2024
1 parent f0f0095 commit 9781602
Showing 1 changed file with 101 additions and 13 deletions.
114 changes: 101 additions & 13 deletions examples/go/faults/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ func CheckErr(err error) {
}
}

func generateFault(fault_id string, event_type grid.FaultEventType, measurement_timestamp int64, fault_current float32, location_probability *float32, used_measurements []*grid.FaultMeasurement, impacted_equipments []string, faulty_equipment *string) *grid.Fault {
func generateFault(
fault_id string,
event_type grid.FaultEventType,
measurement_timestamp int64,
fault_current float32,
location_probability *float32,
used_measurements []*grid.FaultMeasurement,
impacted_equipments []string,
faulty_equipment *string,
) *grid.Fault {
description := "Example fault"

tm := math.Round(float64(time.Now().UnixMilli())/20) * 20
Expand All @@ -45,14 +54,36 @@ func generateFault(fault_id string, event_type grid.FaultEventType, measurement_
return &fault
}

func generateLineFault(fault_id string, event_type grid.FaultEventType, measurement_timestamp int64, fault_current float32, location_probability *float32, used_measurements []*grid.FaultMeasurement, impacted_equipments []string, faulty_equipment *string) *grid.LineFault {

fault := generateFault(fault_id, event_type, measurement_timestamp, fault_current, location_probability, used_measurements, impacted_equipments, faulty_equipment)
func generateLineFault(
fault_id string,
event_type grid.FaultEventType,
measurement_timestamp int64,
fault_current float32,
location_probability *float32,
used_measurements []*grid.FaultMeasurement,
impacted_equipments []string,
faulty_equipment *string,
) *grid.LineFault {

fault := generateFault(
fault_id,
event_type,
measurement_timestamp,
fault_current,
location_probability,
used_measurements,
impacted_equipments,
faulty_equipment,
)

length_from_terminal1 := rand.Float32()
length_uncertainty := float32(100.0)

lineFault := grid.LineFault{Fault: fault, LengthFromTerminal1: &length_from_terminal1, LengthUncertainty: &length_uncertainty}
lineFault := grid.LineFault{
Fault: fault,
LengthFromTerminal1: &length_from_terminal1,
LengthUncertainty: &length_uncertainty,
}

return &lineFault
}
Expand Down Expand Up @@ -128,14 +159,22 @@ func main() {
data := &grid.Fault{}
err := proto.Unmarshal(d.Body, data)
CheckErr(err)
fmt.Printf("Received a fault message: %s, event: %s\n", data.Id, data.FaultEventType)
fmt.Printf(
"Received a fault message: %s, event: %s\n",
data.Id,
data.FaultEventType,
)
}

if d.Headers["type"] == "LineFault" {
data := &grid.LineFault{}
err := proto.Unmarshal(d.Body, data)
CheckErr(err)
fmt.Printf("Received a fault message: %s, event: %s\n", data.Fault.Id, data.Fault.FaultEventType)
fmt.Printf(
"Received a fault message: %s, event: %s\n",
data.Fault.Id,
data.Fault.FaultEventType,
)
}
}
}()
Expand All @@ -148,9 +187,22 @@ func main() {
fault_equipment := new(string)
location_probability := new(float32)
impacted_equipments := []string{"EQ-1", "EQ-2", "EQ-3"}
used_measurements := []*grid.FaultMeasurement{{PositiveSign: true, MeasurementID: "M-1"}, {PositiveSign: true, MeasurementID: "M-1"}, {PositiveSign: true, MeasurementID: "M-1"}}
used_measurements := []*grid.FaultMeasurement{
{PositiveSign: true, MeasurementID: "M-1"},
{PositiveSign: true, MeasurementID: "M-1"},
{PositiveSign: true, MeasurementID: "M-1"},
}

startFaultEvent := generateFault(fault_id, grid.FaultEventType_FAULT_EVENT_TYPE_STARTED, mt, fault_current, location_probability, used_measurements, impacted_equipments, fault_equipment)
startFaultEvent := generateFault(
fault_id,
grid.FaultEventType_FAULT_EVENT_TYPE_STARTED,
mt,
fault_current,
location_probability,
used_measurements,
impacted_equipments,
fault_equipment,
)

header := amqp.Table{
"id": fault_id,
Expand All @@ -162,7 +214,16 @@ func main() {

time.Sleep(20 * time.Millisecond)

endFaultEvent := generateFault(fault_id, grid.FaultEventType_FAULT_EVENT_TYPE_ENDED, mt, fault_current, location_probability, used_measurements, impacted_equipments, fault_equipment)
endFaultEvent := generateFault(
fault_id,
grid.FaultEventType_FAULT_EVENT_TYPE_ENDED,
mt,
fault_current,
location_probability,
used_measurements,
impacted_equipments,
fault_equipment,
)
buf, _ = proto.Marshal(endFaultEvent)
publishMessage(ch, ctx, header, buf)

Expand All @@ -175,21 +236,48 @@ func main() {
"type": "LineFault",
}

location := generateLineFault(fault_id, grid.FaultEventType_FAULT_EVENT_TYPE_LOCATED, mt, fault_current, &probability, used_measurements, impacted_equipments, &equipment)
location := generateLineFault(
fault_id,
grid.FaultEventType_FAULT_EVENT_TYPE_LOCATED,
mt,
fault_current,
&probability,
used_measurements,
impacted_equipments,
&equipment,
)
buf, _ = proto.Marshal(location)
publishMessage(ch, ctx, header, buf)

// second potential location
equipment = "EQ-2"

location = generateLineFault(fault_id, grid.FaultEventType_FAULT_EVENT_TYPE_LOCATED, mt, fault_current, &probability, used_measurements, impacted_equipments, &equipment)
location = generateLineFault(
fault_id,
grid.FaultEventType_FAULT_EVENT_TYPE_LOCATED,
mt,
fault_current,
&probability,
used_measurements,
impacted_equipments,
&equipment,
)
buf, _ = proto.Marshal(location)
publishMessage(ch, ctx, header, buf)

// third potential location
equipment = "EQ-3"

location = generateLineFault(fault_id, grid.FaultEventType_FAULT_EVENT_TYPE_LOCATED, mt, fault_current, &probability, used_measurements, impacted_equipments, &equipment)
location = generateLineFault(
fault_id,
grid.FaultEventType_FAULT_EVENT_TYPE_LOCATED,
mt,
fault_current,
&probability,
used_measurements,
impacted_equipments,
&equipment,
)
buf, _ = proto.Marshal(location)
publishMessage(ch, ctx, header, buf)

Expand Down

0 comments on commit 9781602

Please sign in to comment.