Skip to content

Commit

Permalink
some adjustments to the charting
Browse files Browse the repository at this point in the history
  • Loading branch information
borud committed Apr 4, 2023
1 parent 668f596 commit 5e355c6
Show file tree
Hide file tree
Showing 17 changed files with 396 additions and 31 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
VERSION=0.1.4
VERSION=0.1.6
all: gen test lint vet build

build: pax

pax:
@cd cmd/$@ && go build -o ../../bin/$@

ang:
@cd cmd/$@ && go build -o ../../bin/$@

lint:
@revive ./...

Expand Down
323 changes: 323 additions & 0 deletions frontend/dist/frontend/3rdpartylicenses.txt

Large diffs are not rendered by default.

Binary file added frontend/dist/frontend/favicon.ico
Binary file not shown.
13 changes: 13 additions & 0 deletions frontend/dist/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<title>PAX</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<style>body{font-family:Segoe UI,Tahoma,Geneva,Verdana,sans-serif}</style><link rel="stylesheet" href="styles.c29530ee4fe8253e.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles.c29530ee4fe8253e.css"></noscript></head>

<body>
<app-root></app-root>
<script src="runtime.aaedba49815d2ab0.js" type="module"></script><script src="polyfills.1a4a779d95e3f377.js" type="module"></script><script src="main.a7a0dba0f880d2dd.js" type="module"></script>

</body></html>
1 change: 1 addition & 0 deletions frontend/dist/frontend/main.a7a0dba0f880d2dd.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/dist/frontend/polyfills.1a4a779d95e3f377.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions frontend/dist/frontend/runtime.aaedba49815d2ab0.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/dist/frontend/styles.c29530ee4fe8253e.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body{font-family:Segoe UI,Tahoma,Geneva,Verdana,sans-serif}
8 changes: 8 additions & 0 deletions frontend/frontend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package frontend

import "embed"

// FrontendFS contains the built frontend
//
//go:embed dist/frontend/*
var FrontendFS embed.FS
5 changes: 2 additions & 3 deletions frontend/src/app/src/app/main-chart/main-chart.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ <h1>PAX Counters</h1>
</div>

<div>
<button (click)="showInterval(24)" [ngClass]="{button: true, activeButton: visibleInterval==24}">24h</button>
<button (click)="showInterval(168)" [ngClass]="{button: true, activeButton: visibleInterval==168}">1w</button>
<button (click)="showInterval(24)" [ngClass]="{button: true, activeButton: visibleInterval==24}">1d</button>
<button (click)="showInterval(12)" [ngClass]="{button: true, activeButton: visibleInterval==12}">12h</button>
<button (click)="showInterval(6)" [ngClass]="{button: true, activeButton: visibleInterval==6}">6h</button>
<button (click)="showInterval(3)" [ngClass]="{button: true, activeButton: visibleInterval==3}">3h</button>
<button (click)="showInterval(1)" [ngClass]="{button: true, activeButton: visibleInterval==1}">Last hour</button>
</div>
<!--<div *ngFor="let sampleSet of dataPoints">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class MainChartComponent implements OnInit, AfterViewInit {
errorMessage: string = "";
lastPoll: Date = new Date();
chart?: Chart<any>;
visibleInterval: number = 6;
visibleInterval: number = 24;

hasError(): boolean {
return this.errorMessage != "";
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/lab5e/pax
go 1.20

require (
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2
github.com/jessevdk/go-flags v1.5.0
Expand All @@ -19,6 +20,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/eclipse/paho.golang v0.10.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -110,6 +112,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
Expand Down
32 changes: 11 additions & 21 deletions pkg/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package server

import (
"context"
"fmt"
"io/fs"
"log"
"net"
"net/http"
"os"

"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/lab5e/pax/doc"
"github.com/lab5e/pax/frontend"
paxv1 "github.com/lab5e/pax/pkg/pax/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -34,13 +37,18 @@ func (s *Server) startHTTP() error {

swaggerFiles := http.FileServer(http.FS(doc.SwaggerFiles))

frontendFS, err := fs.Sub(frontend.FrontendFS, "dist/frontend")
if err != nil {
return err
}

mux := mux.NewRouter()
mux.HandleFunc("/", s.handleIndex).Methods("GET")
mux.PathPrefix("/doc/").Handler(http.StripPrefix("/doc/", swaggerFiles)).Methods("GET")
mux.PathPrefix("/api/v1").Handler(restMux).Methods("GET")
mux.PathPrefix("/").Handler(http.FileServer(http.FS(frontendFS)))

s.httpServer = &http.Server{
Handler: addCORSHeaders(mux.ServeHTTP),
Handler: handlers.LoggingHandler(os.Stdout, addCORSHeaders(mux.ServeHTTP)),
}

go func() {
Expand All @@ -55,21 +63,3 @@ func (s *Server) startHTTP() error {

return nil
}

func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PAX</title>
</head>
<body>
<ul>
<li><a href="/api/v1/data">Data endpoint</a></li>
<li><a href="/api/v1/devices">Devices endpoint</a></li>
<li><a href="/doc/swagger/pax/v1/">OpenAPI</a></li>
</body>
</html>
`)
}
20 changes: 18 additions & 2 deletions pkg/service/s_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ import (
"context"
"log"

"github.com/lab5e/pax/pkg/model"
paxv1 "github.com/lab5e/pax/pkg/pax/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (s *service) ListData(ctx context.Context, req *paxv1.ListDataRequest) (*paxv1.ListDataResponse, error) {
devices, err := s.db.ListDevices()
if err != nil {
log.Printf("error listing devices: %v", err)
return nil, status.Error(codes.Internal, "internal error")
}

deviceMap := make(map[string]model.Device)
for _, device := range devices {
deviceMap[device.ID] = device
}

samples, err := s.db.ListSamples(req.Since, req.Until, int(req.Limit))
if err != nil {
log.Printf("error listing samples, since=%d until=%d limit=%d: %v", req.Since, req.Until, req.Limit, err)
Expand All @@ -25,9 +37,13 @@ func (s *service) ListData(ctx context.Context, req *paxv1.ListDataRequest) (*pa
// build response
dataArray := []*paxv1.Data{}
for k, v := range byDeviceIDMap {
device := deviceMap[k]
dataArray = append(dataArray, &paxv1.Data{
DeviceId: k,
Samples: v,
DeviceId: k,
DeviceName: device.Name,
Lat: device.Lat,
Lon: device.Lon,
Samples: v,
})
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/store/sqlitestore/t_sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type sampleStatements struct {
}

const (
hardRowLimit = 50000
defaultLimit = 20000
hardRowLimit = 200000
defaultLimit = 150000
)

func (s *sqliteStore) initSampleStatements() error {
Expand Down
5 changes: 4 additions & 1 deletion proto/pax/v1/data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import "pax/v1/sample.proto";

message Data {
string device_id = 1;
repeated Sample samples = 2;
string device_name = 2;
double lat = 3;
double lon = 4;
repeated Sample samples = 5;
}

message ListDataRequest {
Expand Down

0 comments on commit 5e355c6

Please sign in to comment.