-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2150f3
commit f0315ab
Showing
255 changed files
with
7,547 additions
and
5,491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: Build Docker Image | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE: anyshake/observer | ||
|
||
jobs: | ||
build_docker_image: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
packages: write | ||
contents: read | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Login to Registry | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and Push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
push: true | ||
file: ./Dockerfile | ||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE }}:latest | ||
|
||
- name: Inspect Image | ||
run: | | ||
docker buildx imagetools inspect \ | ||
${{ env.REGISTRY }}/${{ env.IMAGE }}:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,5 @@ _testmain.go | |
*.test | ||
*.prof | ||
|
||
# AnyShake Observer build files | ||
build/dist* | ||
build/release* | ||
build/dist | ||
frontend/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM golang:alpine AS builder | ||
|
||
RUN apk update && apk add --no-cache git bash wget curl make npm | ||
WORKDIR /build | ||
RUN git clone --progress https://github.com/anyshake/observer.git ./observer && \ | ||
export VERSION=`cat ./observer/VERSION` && \ | ||
cd ./observer/frontend/src && \ | ||
npm install && \ | ||
make && \ | ||
cd ../../docs && \ | ||
make && \ | ||
cd ../cmd && \ | ||
go mod tidy && \ | ||
go build -ldflags "-s -w -X main.version=$VERSION -X main.release=docker_build" -trimpath -o /tmp/observer *.go | ||
|
||
FROM alpine | ||
|
||
COPY --from=builder /tmp/observer /usr/bin/observer | ||
RUN chmod 755 /usr/bin/observer && \ | ||
mkdir -p /etc/observer | ||
|
||
CMD ["observer", "-config=/etc/observer/config.json"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v2.12.5 | ||
v3.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package devel | ||
|
||
func (h *Devel) GetApiName() string { | ||
return "devel" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package history | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
v1 "github.com/anyshake/observer/api/v1" | ||
"github.com/anyshake/observer/drivers/dao/tables" | ||
"github.com/anyshake/observer/drivers/explorer" | ||
) | ||
|
||
func (h *History) filterHistory(startTime, endTime int64, maxDuration time.Duration, resolver *v1.Resolver) ([]explorer.ExplorerData, error) { | ||
if endTime-startTime > maxDuration.Milliseconds() { | ||
return nil, fmt.Errorf("duration is too large") | ||
} | ||
|
||
var ( | ||
adcCountModel tables.AdcCount | ||
adcCountData []tables.AdcCount | ||
) | ||
err := resolver.Database. | ||
Table(adcCountModel.GetName()). | ||
Where("timestamp >= ? AND timestamp <= ?", startTime, endTime). | ||
Order("timestamp ASC"). | ||
Find(&adcCountData). | ||
Error | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var explorerData []explorer.ExplorerData | ||
for _, record := range adcCountData { | ||
explorerData = append(explorerData, explorer.ExplorerData{ | ||
Timestamp: record.Timestamp, | ||
SampleRate: record.SampleRate, | ||
Z_Axis: record.Z_Axis, | ||
E_Axis: record.E_Axis, | ||
N_Axis: record.N_Axis, | ||
}) | ||
} | ||
|
||
if len(explorerData) == 0 { | ||
return nil, fmt.Errorf("no data available for the given time range") | ||
} | ||
return explorerData, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package history | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
v1 "github.com/anyshake/observer/api/v1" | ||
"github.com/anyshake/observer/drivers/explorer" | ||
"github.com/anyshake/observer/server/response" | ||
"github.com/anyshake/observer/utils/logger" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// @Summary AnyShake Observer waveform history | ||
// @Description Get waveform count data in specified time range, channel and format, the maximum duration of the waveform data to be exported is 24 hours for JSON and 1 hour for SAC | ||
// @Router /history [post] | ||
// @Accept application/x-www-form-urlencoded | ||
// @Produce application/json | ||
// @Produce application/octet-stream | ||
// @Param start_time formData int true "Start timestamp of the waveform data to be queried, in milliseconds (unix timestamp)" | ||
// @Param end_time formData int true "End timestamp of the waveform data to be queried, in milliseconds (unix timestamp)" | ||
// @Param format formData string true "Format of the waveform data to be queried, `json` or `sac`" | ||
// @Param channel formData string false "Channel of the waveform, `Z`, `E` or `N`, reuqired when format is `sac`" | ||
// @Failure 400 {object} response.HttpResponse "Failed to export waveform data due to invalid format or channel" | ||
// @Failure 410 {object} response.HttpResponse "Failed to export waveform data due to no data available" | ||
// @Failure 500 {object} response.HttpResponse "Failed to export waveform data due to failed to read data source" | ||
// @Success 200 {object} response.HttpResponse{data=[]explorer.ExplorerData} "Successfully exported the waveform data" | ||
func (h *History) Register(rg *gin.RouterGroup, resolver *v1.Resolver) error { | ||
rg.POST("/history", func(c *gin.Context) { | ||
var binding historyBinding | ||
if err := c.ShouldBind(&binding); err != nil { | ||
logger.GetLogger(h.GetApiName()).Errorln(err) | ||
response.Error(c, http.StatusBadRequest) | ||
return | ||
} | ||
|
||
switch binding.Format { | ||
case "json": | ||
result, err := h.filterHistory(binding.StartTime, binding.EndTime, JSON_MAX_DURATION, resolver) | ||
if err != nil { | ||
logger.GetLogger(h.GetApiName()).Errorln(err) | ||
response.Error(c, http.StatusGone) | ||
return | ||
} | ||
response.Message(c, "The waveform data was successfully filtered", result) | ||
return | ||
case "sac": | ||
result, err := h.filterHistory(binding.StartTime, binding.EndTime, SAC_MAX_DURATION, resolver) | ||
if err != nil { | ||
logger.GetLogger(h.GetApiName()).Errorln(err) | ||
response.Error(c, http.StatusGone) | ||
return | ||
} | ||
if binding.Channel != explorer.EXPLORER_CHANNEL_CODE_Z && | ||
binding.Channel != explorer.EXPLORER_CHANNEL_CODE_E && | ||
binding.Channel != explorer.EXPLORER_CHANNEL_CODE_N { | ||
err := fmt.Errorf("no channel was selected") | ||
logger.GetLogger(h.GetApiName()).Errorln(err) | ||
response.Error(c, http.StatusBadRequest) | ||
return | ||
} | ||
fileName, dataBytes, err := h.getSACBytes( | ||
result, | ||
resolver.Config.Stream.Station, | ||
resolver.Config.Stream.Network, | ||
resolver.Config.Stream.Location, | ||
resolver.Config.Stream.Channel, | ||
binding.Channel, | ||
) | ||
if err != nil { | ||
logger.GetLogger(h.GetApiName()).Errorln(err) | ||
response.Error(c, http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
response.File(c, fileName, dataBytes) | ||
return | ||
} | ||
|
||
response.Error(c, http.StatusBadRequest) | ||
}) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package history | ||
|
||
func (h *History) GetApiName() string { | ||
return "history" | ||
} |
Oops, something went wrong.