Skip to content

Commit

Permalink
Performance optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
bclswl0827 committed Dec 10, 2023
1 parent c59c540 commit 41a621d
Show file tree
Hide file tree
Showing 43 changed files with 477 additions and 167 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.2.2p
v2.2.3p
25 changes: 14 additions & 11 deletions app/station/station.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ package station

import (
"github.com/bclswl0827/observer/feature"
"github.com/bclswl0827/observer/utils/duration"
)

func getStation(options *feature.FeatureOptions) System {
_, ts := duration.Timestamp(options.Status.System.Offset)
return System{
Status: options.Status.System,
Station: options.Config.Station.Name,
UUID: options.Config.Station.UUID,
Location: getLocation(options.Config),
Geophone: getGeophone(options.Config),
ADC: getADC(options.Config),
OS: getOS(),
CPU: getCPU(),
Disk: getDisk(),
Memory: getMemory(),
Uptime: getUptime(),
Timestamp: ts,
Status: options.Status.System,
Station: options.Config.Station.Name,
UUID: options.Config.Station.UUID,
Location: getLocation(options.Config),
Geophone: getGeophone(options.Config),
ADC: getADC(options.Config),
OS: getOS(),
CPU: getCPU(),
Disk: getDisk(),
Memory: getMemory(),
Uptime: getUptime(),
}
}
23 changes: 12 additions & 11 deletions app/station/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ type Location struct {
}

type System struct {
UUID string `json:"uuid"`
Station string `json:"station"`
Uptime int64 `json:"uptime"`
Memory Memory `json:"memory"`
Disk Disk `json:"disk"`
ADC ADC `json:"adc"`
OS OS `json:"os"`
CPU CPU `json:"cpu"`
Geophone Geophone `json:"geophone"`
Location Location `json:"location"`
Status *publisher.System `json:"status"`
UUID string `json:"uuid"`
Station string `json:"station"`
Timestamp int64 `json:"timestamp"`
Uptime int64 `json:"uptime"`
Memory Memory `json:"memory"`
Disk Disk `json:"disk"`
ADC ADC `json:"adc"`
OS OS `json:"os"`
CPU CPU `json:"cpu"`
Geophone Geophone `json:"geophone"`
Location Location `json:"location"`
Status *publisher.System `json:"status"`
}
9 changes: 2 additions & 7 deletions app/trace/ceic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ type CEIC struct {
DataSourceCache
}

func (c *CEIC) Property() (string, string) {
const (
NAME string = "中国地震台网中心"
VALUE string = "CEIC"
)

return NAME, VALUE
func (c *CEIC) Property() string {
return "中国地震台网中心"
}

func (c *CEIC) Fetch() ([]byte, error) {
Expand Down
9 changes: 2 additions & 7 deletions app/trace/cwa.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ type CWA struct {
DataSourceCache
}

func (c *CWA) Property() (string, string) {
const (
NAME string = "交通部中央氣象局"
VALUE string = "CWA"
)

return NAME, VALUE
func (c *CWA) Property() string {
return "交通部中央氣象局"
}

func (c *CWA) createGFWBypasser() *http.Transport {
Expand Down
9 changes: 2 additions & 7 deletions app/trace/hko.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ type HKO struct {
DataSourceCache
}

func (h *HKO) Property() (string, string) {
const (
NAME string = "天文台全球地震資訊網"
VALUE string = "HKO"
)

return NAME, VALUE
func (h *HKO) Property() string {
return "天文台全球地震資訊網"
}

func (h *HKO) Fetch() ([]byte, error) {
Expand Down
9 changes: 2 additions & 7 deletions app/trace/jma.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ type JMA struct {
DataSourceCache
}

func (j *JMA) Property() (string, string) {
const (
NAME string = "気象庁地震情報"
VALUE string = "JMA"
)

return NAME, VALUE
func (j *JMA) Property() string {
return "気象庁地震情報"
}

func (j *JMA) Fetch() ([]byte, error) {
Expand Down
41 changes: 22 additions & 19 deletions app/trace/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ import (
// @Failure 500 {object} response.HttpResponse "Failed to read earthquake event list due to failed to read data source"
// @Success 200 {object} response.HttpResponse{data=[]Event} "Successfully read the list of earthquake events"
func (t *Trace) RegisterModule(rg *gin.RouterGroup, options *app.ServerOptions) {
sources := []DataSource{
&SCEA_E{}, &SCEA_B{}, &CEIC{},
&USGS{}, &JMA{}, &CWA{}, &HKO{},
sources := map[string]DataSource{
"CWA": &CWA{},
"HKO": &HKO{},
"JMA": &JMA{},
"CEIC": &CEIC{},
"USGS": &USGS{},
"SCEA_E": &SCEA_E{},
"SCEA_B": &SCEA_B{},
}

rg.POST("/trace", func(c *gin.Context) {
Expand All @@ -37,11 +42,11 @@ func (t *Trace) RegisterModule(rg *gin.RouterGroup, options *app.ServerOptions)
}

var list []availableSources
for _, v := range sources {
name, value := v.Property()
for k, v := range sources {
name := v.Property()
list = append(list, availableSources{
Name: name,
Value: value,
Value: k,
})
}

Expand All @@ -50,22 +55,20 @@ func (t *Trace) RegisterModule(rg *gin.RouterGroup, options *app.ServerOptions)
}

var (
latitude = options.FeatureOptions.Config.Station.Latitude
longitude = options.FeatureOptions.Config.Station.Longitude
source, ok = sources[binding.Source]
latitude = options.FeatureOptions.Config.Station.Latitude
longitude = options.FeatureOptions.Config.Station.Longitude
)
for _, v := range sources {
_, value := v.Property()
if value == binding.Source {
events, err := v.List(latitude, longitude)
if err != nil {
response.Error(c, http.StatusInternalServerError)
return
}

sortByTimestamp(events)
response.Message(c, "Successfully read the list of earthquake events", events)
if ok {
events, err := source.List(latitude, longitude)
if err != nil {
response.Error(c, http.StatusInternalServerError)
return
}

sortByTimestamp(events)
response.Message(c, "Successfully read the list of earthquake events", events)
return
}

response.Error(c, http.StatusBadRequest)
Expand Down
9 changes: 2 additions & 7 deletions app/trace/scea-b.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ type SCEA_B struct {
DataSourceCache
}

func (s *SCEA_B) Property() (string, string) {
const (
NAME string = "四川地震局(速报)"
VALUE string = "SCEA-B"
)

return NAME, VALUE
func (s *SCEA_B) Property() string {
return "四川地震局(速报)"
}

func (s *SCEA_B) Fetch() ([]byte, error) {
Expand Down
9 changes: 2 additions & 7 deletions app/trace/scea-e.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ type SCEA_E struct {
DataSourceCache
}

func (s *SCEA_E) Property() (string, string) {
const (
NAME string = "四川地震局(预警)"
VALUE string = "SCEA-E"
)

return NAME, VALUE
func (s *SCEA_E) Property() string {
return "四川地震局(预警)"
}

func (s *SCEA_E) Fetch() ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion app/trace/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type Event struct {
}

type DataSource interface {
Property() string
Fetch() ([]byte, error)
Property() (string, string)
Parse([]byte) (map[string]any, error)
List(latitude, longitude float64) ([]Event, error)
Format(float64, float64, map[string]any) ([]Event, error)
Expand Down
9 changes: 2 additions & 7 deletions app/trace/usgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ type USGS struct {
DataSourceCache
}

func (u *USGS) Property() (string, string) {
const (
NAME string = "United States Geological Survey"
VALUE string = "USGS"
)

return NAME, VALUE
func (u *USGS) Property() string {
return "United States Geological Survey"
}

func (u *USGS) Fetch() ([]byte, error) {
Expand Down
3 changes: 3 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ const docTemplate = `{
"status": {
"$ref": "#/definitions/publisher.System"
},
"timestamp": {
"type": "integer"
},
"uptime": {
"type": "integer"
},
Expand Down
3 changes: 3 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@
"status": {
"$ref": "#/definitions/publisher.System"
},
"timestamp": {
"type": "integer"
},
"uptime": {
"type": "integer"
},
Expand Down
2 changes: 2 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ definitions:
type: string
status:
$ref: '#/definitions/publisher.System'
timestamp:
type: integer
uptime:
type: integer
uuid:
Expand Down
22 changes: 11 additions & 11 deletions frontend/dist/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"files": {
"main.css": "/static/css/main.3d547ccc.css",
"main.js": "/static/js/main.ea5b2235.js",
"static/css/278.525e2941.chunk.css": "/static/css/278.525e2941.chunk.css",
"static/js/278.f2bbf51e.chunk.js": "/static/js/278.f2bbf51e.chunk.js",
"static/js/967.8f28312d.chunk.js": "/static/js/967.8f28312d.chunk.js",
"static/js/555.c29bef82.chunk.js": "/static/js/555.c29bef82.chunk.js",
"static/js/756.d56da6cc.chunk.js": "/static/js/756.d56da6cc.chunk.js",
"static/js/886.2b35e155.chunk.js": "/static/js/886.2b35e155.chunk.js",
"main.js": "/static/js/main.fa967e24.js",
"static/css/290.525e2941.chunk.css": "/static/css/290.525e2941.chunk.css",
"static/js/290.98f2a2d3.chunk.js": "/static/js/290.98f2a2d3.chunk.js",
"static/js/78.2f297237.chunk.js": "/static/js/78.2f297237.chunk.js",
"static/js/920.12311b86.chunk.js": "/static/js/920.12311b86.chunk.js",
"static/js/253.e64c7cc8.chunk.js": "/static/js/253.e64c7cc8.chunk.js",
"static/js/332.587820cf.chunk.js": "/static/js/332.587820cf.chunk.js",
"static/js/377.f0e1c66a.chunk.js": "/static/js/377.f0e1c66a.chunk.js",
"static/js/453.30461b97.chunk.js": "/static/js/453.30461b97.chunk.js",
"static/js/59.a77c052b.chunk.js": "/static/js/59.a77c052b.chunk.js",
"static/js/596.0088f6dd.chunk.js": "/static/js/596.0088f6dd.chunk.js",
"static/js/366.14cf3b89.chunk.js": "/static/js/366.14cf3b89.chunk.js",
"static/js/165.41b9296d.chunk.js": "/static/js/165.41b9296d.chunk.js",
"static/js/979.14e4e415.chunk.js": "/static/js/979.14e4e415.chunk.js",
"static/js/165.7bfcd6cb.chunk.js": "/static/js/165.7bfcd6cb.chunk.js",
"static/js/979.de18ef96.chunk.js": "/static/js/979.de18ef96.chunk.js",
"static/js/822.ae40dac1.chunk.js": "/static/js/822.ae40dac1.chunk.js",
"static/js/912.b91c9724.chunk.js": "/static/js/912.b91c9724.chunk.js",
"static/js/730.31759149.chunk.js": "/static/js/730.31759149.chunk.js",
"static/js/730.444d5068.chunk.js": "/static/js/730.444d5068.chunk.js",
"static/media/gear-solid.svg": "/static/media/gear-solid.bf34f9d52ff44a67baec8a0d4220d3a3.svg",
"static/media/bug-solid.svg": "/static/media/bug-solid.7f781f9ddd35c29f11111e36602dcc87.svg",
"static/media/earth-americas-solid.svg": "/static/media/earth-americas-solid.4105ee3951f1c7ac60331fccafc17c1f.svg",
Expand Down Expand Up @@ -47,6 +47,6 @@
},
"entrypoints": [
"static/css/main.3d547ccc.css",
"static/js/main.ea5b2235.js"
"static/js/main.fa967e24.js"
]
}
2 changes: 1 addition & 1 deletion frontend/dist/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/><link rel="icon" href="/favicon.ico"/><link rel="manifest" href="/manifest.json"/><script defer="defer" src="/static/js/main.ea5b2235.js"></script><link href="/static/css/main.3d547ccc.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
<!doctype html><html><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"/><link rel="icon" href="/favicon.ico"/><link rel="manifest" href="/manifest.json"/><script defer="defer" src="/static/js/main.fa967e24.js"></script><link href="/static/css/main.3d547ccc.css" rel="stylesheet"></head><body><div id="root"></div></body></html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 41a621d

Please sign in to comment.