<commit_before>package web

import (
	"github.com/gorilla/mux"
	"github.com/jimmysawczuk/power-monitor/monitor"

	"encoding/json"
	"html/template"
	// "log"
	"net/http"
	"strconv"
	"time"
)

var activeMonitor *monitor.Monitor
var startTime time.Time
var indexTmpl = template.Must(template.New("name").Parse(string(MustAsset("web/templates/index.html"))))

func GetRouter(m *monitor.Monitor) *mux.Router {
	activeMonitor = m
	startTime = time.Now()

	r := mux.NewRouter()
	r.HandleFunc("/", getIndex)
	r.HandleFunc("/api/snapshots", getSnapshots)
	r.PathPrefix("/").HandlerFunc(getStaticFile)
	return r
}
func getStaticFile(w http.ResponseWriter, r *http.Request) {
	path := r.URL.Path
	by, err := Asset("web/static" + path)
	if err != nil {
		w.WriteHeader(404)
		return
	}
	w.WriteHeader(200)
	w.Write(by)
}

func getIndex(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(200)
	indexTmpl.Execute(w, map[string]interface{}{
		"StartTime": startTime,
		"Interval":  int64(activeMonitor.Interval / 1e6),
		"Mode":      "Release",
	})
}

func getSnapshots(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()

	now := time.Now()

	recent := activeMonitor.GetRecentSnapshots().Filter(func(s monitor.Snapshot) bool {<commit_msg>Switching to release mode<commit_after>package web

import (
	"github.com/gorilla/mux"
	"github.com/jimmysawczuk/power-monitor/monitor"

	"encoding/json"
	"html/template"
	// "log"
	"net/http"
	"strconv"
	"time"
)

var activeMonitor *monitor.Monitor
var startTime time.Time
var indexTmpl = template.Must(template.New("name").Parse(string(MustAsset("web/templates/index.html"))))

func GetRouter(m *monitor.Monitor) *mux.Router {
	activeMonitor = m
	startTime = time.Now()

	r := mux.NewRouter()
	r.HandleFunc("/", getIndex)
	r.HandleFunc("/api/snapshots", getSnapshots)
	r.PathPrefix("/").HandlerFunc(getStaticFile)
	return r
}
func getStaticFile(w http.ResponseWriter, r *http.Request) {
	path := r.URL.Path
	by, err := Asset("web/static" + path)
	if err != nil {
		w.WriteHeader(404)
		return
	}
	w.WriteHeader(200)
	w.Write(by)
}

func getIndex(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(200)
	indexTmpl.Execute(w, map[string]interface{}{
		"StartTime": startTime,
		"Interval":  int64(activeMonitor.Interval / 1e6),
		"Mode":      "release",
	})
}

func getSnapshots(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()

	now := time.Now()

	recent := activeMonitor.GetRecentSnapshots().Filter(func(s monitor.Snapshot) bool {
{'fraction_non_alphanumeric': 0.16035455278001612, 'fraction_numerical': 0.010475423045930701, 'mean_word_length': 4.8014018691588785, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '286294', 'n_tokens_mistral': 957, 'n_tokens_neox': 912, 'n_words': 167}