Skip to content

Commit

Permalink
Add median green length per cell
Browse files Browse the repository at this point in the history
  • Loading branch information
adeveloper-wq committed Nov 20, 2023
1 parent f35bfa6 commit 23a4961
Show file tree
Hide file tree
Showing 7 changed files with 319 additions and 27 deletions.
2 changes: 1 addition & 1 deletion studies/db/go_rewrite/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
processed_things.json
processed_things*.json
3 changes: 1 addition & 2 deletions studies/db/go_rewrite/notebooks/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
things.json
processed_things_2023_11_15.json
processed_things_old.json
processed_things*.json
5 changes: 3 additions & 2 deletions studies/db/go_rewrite/notebooks/studies_charts_meta.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -259,7 +259,8 @@
" single_ax.set_ylabel(histogram_data_to_plot[index][\"ylabel\"])\n",
" single_ax.set_title(histogram_data_to_plot[index][\"title\"])\n",
" if histogram_data_to_plot[index][\"xlim\"] is not None:\n",
" single_ax.set_xlim(histogram_data_to_plot[index][\"xlim\"])"
" single_ax.set_xlim(histogram_data_to_plot[index][\"xlim\"])\n",
" # single_ax.set_yscale('log')"
]
}
],
Expand Down
24 changes: 12 additions & 12 deletions studies/db/go_rewrite/notebooks/studies_charts_weekly.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions studies/db/go_rewrite/runner/runner_complete_cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func RunCompleteCell(tldThings []things.TLDThing, suffixName string) map[string]
processedThings[name].MetricsSP[dayIdx] = thing.MetricsSP[dayIdx]
processedThings[name].MedianShifts[dayIdx] = thing.MedianShifts[dayIdx]
processedThings[name].MetricsRelativeGreenDistance[dayIdx] = thing.MetricsRelativeGreenDistance[dayIdx]
processedThings[name].MedianGreenLengths[dayIdx] = thing.MedianGreenLengths[dayIdx]
}
}
}
Expand Down
38 changes: 30 additions & 8 deletions studies/db/go_rewrite/things/thing.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ type Thing struct {
TotalInvalidCycleMissingCount int32

// Metrics
Metrics [7][24]float64
Metrics [7][24]float64
MetricsRelativeGreenDistance [7][24]float64
MetricsSP [7][24]float64
MedianShifts [7][24]float64
MetricsSP [7][24]float64
MedianShifts [7][24]float64
MedianGreenLengths [7][24]float64
}

func NewThing(name string, validation bool, retrieveAllCycleCleanupStats bool) *Thing {
Expand Down Expand Up @@ -269,7 +270,6 @@ func (thing *Thing) getGreenRelativeDistance(cycle1 cycle, cycle2 cycle) *float6
return &relativeDistance
}


func (thing *Thing) getGreenProbabilities(cycles []cycle) []float64 {
probabilities := make([]float64, 0)
maxLength := 0
Expand Down Expand Up @@ -319,7 +319,7 @@ func (thing *Thing) getGreenIndices(cycle cycle) []int {
indices = append(indices, idx)
} else if previousResult == 3 && result != 3 {
indices = append(indices, idx-1)
}
}
if idx == len(cycle.results)-1 && result == 3 {
indices = append(indices, idx)
}
Expand All @@ -329,22 +329,35 @@ func (thing *Thing) getGreenIndices(cycle cycle) []int {
return indices
}

func (thing *Thing) getGreenLength(cycle cycle) float64 {
greenLength := 0.0
for _, result := range cycle.results {
if result == 3 {
greenLength++
}
}

return greenLength
}

func (thing *Thing) CalculateMetrics(day int, hour int) {
distances := make([]float64, 0)
relativeGreenDistances := make([]float64, 0)
totalGreenDiffs := make([]float64, 0)
greenLengths := make([]float64, 0)
cycles := []cycle{}
for _, cellCycles := range thing.cycles {
for idx, cycle := range cellCycles {
cycles = append(cycles, cycle)
greenIndices := thing.getGreenIndices(cycle)
greenLengths = append(greenLengths, thing.getGreenLength(cycle))
if idx >= len(cellCycles)-1 {
break
}
nextGreenIndices := thing.getGreenIndices(cellCycles[idx+1])

maxGreenIndicesPerCycle := max(len(greenIndices), len(nextGreenIndices))

for i := 0; i < maxGreenIndicesPerCycle; i++ {
if i >= len(greenIndices) || i >= len(nextGreenIndices) {
continue
Expand All @@ -353,7 +366,6 @@ func (thing *Thing) CalculateMetrics(day int, hour int) {
totalGreenDiffs = append(totalGreenDiffs, float64(nextGreenIndices[i]-greenIndices[i]))
}


distances = append(distances, thing.phaseWiseDistance(cycle, cellCycles[idx+1]))
relativeDistance := thing.getGreenRelativeDistance(cycle, cellCycles[idx+1])
if relativeDistance != nil {
Expand All @@ -362,9 +374,19 @@ func (thing *Thing) CalculateMetrics(day int, hour int) {
}
}

if len(greenLengths) == 0 {
thing.MedianGreenLengths[day][hour] = -1.0
} else {
medianGreenLength, err := stats.Median(greenLengths)
if err != nil {
panic(err)
}
thing.MedianGreenLengths[day][hour] = medianGreenLength
}

if len(totalGreenDiffs) == 0 {
thing.MedianShifts[day][hour] = -999999
}else {
} else {
medianShift, err := stats.Median(totalGreenDiffs)
if err != nil {
panic(err)
Expand Down
Loading

0 comments on commit 23a4961

Please sign in to comment.