lint: remove unused code from platform/label_studio, email, dashboard, sync
- Delete sync/text.go, sync/tile.go, platform/dashboard.go (entirely unused) - Remove unused vars/funcs from platform/label_studio.go (9 items) - Remove contentEmailInitial, contentEmailReportConfirmation, newContentEmailNotificationConfirmation, contentEmailBase from platform/email
This commit is contained in:
parent
10046f1edb
commit
e9127466f0
7 changed files with 1 additions and 299 deletions
|
|
@ -1,67 +0,0 @@
|
|||
package platform
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
)
|
||||
|
||||
type ServiceRequestSummary struct {
|
||||
Date time.Time
|
||||
Location string
|
||||
Status string
|
||||
}
|
||||
type contentDashboard struct {
|
||||
CountTraps int
|
||||
CountMosquitoSources int
|
||||
CountServiceRequests int
|
||||
IsSyncOngoing bool
|
||||
LastSync *time.Time
|
||||
RecentRequests []ServiceRequestSummary
|
||||
}
|
||||
|
||||
func getDashboardData(ctx context.Context, user User) (*contentDashboard, *nhttp.ErrorWithStatus) {
|
||||
var lastSync *time.Time
|
||||
sync, err := user.Organization.FieldseekerSyncLatest(ctx)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("Failed to get syncs: %w", err)
|
||||
} else if sync != nil {
|
||||
lastSync = &sync.Created
|
||||
}
|
||||
is_syncing := user.Organization.IsSyncOngoing()
|
||||
count_trap, err := user.Organization.CountTrap(ctx)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("Failed to get trap count: %w", err)
|
||||
}
|
||||
count_source, err := user.Organization.CountTrap(ctx)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("Failed to get source count: %w", err)
|
||||
}
|
||||
count_service, err := user.Organization.CountServiceRequest(ctx)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("Failed to get service count: %w", err)
|
||||
}
|
||||
service_request_recent, err := user.Organization.ServiceRequestRecent(ctx)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("Failed to get recent service: %w", err)
|
||||
}
|
||||
|
||||
requests := make([]ServiceRequestSummary, 0)
|
||||
for _, r := range service_request_recent {
|
||||
requests = append(requests, ServiceRequestSummary{
|
||||
Date: r.Creationdate.MustGet(),
|
||||
Location: r.Reqaddr1.MustGet(),
|
||||
Status: "Completed",
|
||||
})
|
||||
}
|
||||
content := contentDashboard{
|
||||
CountTraps: int(count_trap),
|
||||
CountMosquitoSources: int(count_source),
|
||||
CountServiceRequests: int(count_service),
|
||||
IsSyncOngoing: is_syncing,
|
||||
LastSync: lastSync,
|
||||
RecentRequests: requests,
|
||||
}
|
||||
return &content, nil
|
||||
}
|
||||
|
|
@ -10,12 +10,6 @@ import (
|
|||
//"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type contentEmailInitial struct {
|
||||
Base contentEmailBase
|
||||
Destination string
|
||||
URLSubscribe string
|
||||
}
|
||||
|
||||
func maybeSendInitialEmail(ctx context.Context, destination string) error {
|
||||
err := EnsureInDB(ctx, destination)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@ import (
|
|||
//"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type contentEmailReportConfirmation struct {
|
||||
Base contentEmailBase
|
||||
URLReportStatus string
|
||||
}
|
||||
|
||||
func SendReportConfirmation(ctx context.Context, destination, report_id string) error {
|
||||
err := maybeSendInitialEmail(ctx, destination)
|
||||
if err != nil {
|
||||
|
|
@ -31,7 +26,4 @@ func SendReportConfirmation(ctx context.Context, destination, report_id string)
|
|||
return sendEmailBegin(ctx, config.ForwardEmailRMOAddress, destination, templateReportNotificationConfirmationID, subject, data)
|
||||
}
|
||||
|
||||
func newContentEmailNotificationConfirmation(report_id string) (result contentEmailReportConfirmation) {
|
||||
result.URLReportStatus = config.MakeURLReport("/status/%s", report_id)
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,12 +38,6 @@ var (
|
|||
templateReportNotificationConfirmationID int32
|
||||
)
|
||||
|
||||
type contentEmailBase struct {
|
||||
URLLogo string
|
||||
URLUnsubscribe string
|
||||
URLViewInBrowser string
|
||||
}
|
||||
|
||||
type ContentEmailRender struct {
|
||||
IsBrowser bool
|
||||
C any
|
||||
|
|
|
|||
|
|
@ -2,22 +2,9 @@ package platform
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/label-studio"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/minio"
|
||||
//"github.com/google/uuid"
|
||||
)
|
||||
|
||||
var labelStudioClient *labelstudio.Client
|
||||
var labelStudioProject *labelstudio.Project
|
||||
var minioClient *minio.Client
|
||||
|
||||
func initializeLabelStudio() error {
|
||||
return nil
|
||||
/*
|
||||
|
|
@ -41,37 +28,6 @@ func initializeLabelStudio() error {
|
|||
return nil
|
||||
*/
|
||||
}
|
||||
func createMinioClient() (*minio.Client, error) {
|
||||
baseUrl := os.Getenv("S3_BASE_URL")
|
||||
accessKeyID := os.Getenv("S3_ACCESS_KEY_ID")
|
||||
secretAccessKey := os.Getenv("S3_SECRET_ACCESS_KEY")
|
||||
|
||||
client, err := minio.NewClient(baseUrl, accessKeyID, secretAccessKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Println("Created minio client")
|
||||
return client, err
|
||||
}
|
||||
func createLabelStudioClient() (*labelstudio.Client, error) {
|
||||
// Initialize the client with your Label Studio base URL and API key
|
||||
labelStudioApiKey := os.Getenv("LABEL_STUDIO_API_KEY")
|
||||
labelStudioBaseUrl := os.Getenv("LABEL_STUDIO_BASE_URL")
|
||||
labelStudioClient := labelstudio.NewClient(labelStudioBaseUrl, labelStudioApiKey)
|
||||
log.Println("Created label studio client")
|
||||
|
||||
// Get and store the access token
|
||||
err := labelStudioClient.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to get access token: %v", err)
|
||||
}
|
||||
log.Println("Got label studio client access token")
|
||||
|
||||
return labelStudioClient, nil
|
||||
}
|
||||
func noteAudioGetLatest(ctx context.Context, uuid string) (*models.NoteAudio, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func jobLabelStudioAudioCreate(ctx context.Context, row_id int32) error {
|
||||
return fmt.Errorf("label studio integration has been disabled")
|
||||
/*
|
||||
|
|
@ -104,100 +60,4 @@ func jobLabelStudioAudioCreate(ctx context.Context, row_id int32) error {
|
|||
*/
|
||||
}
|
||||
|
||||
func createTask(client *labelstudio.Client, project *labelstudio.Project, minioClient *minio.Client, bucket string, customer string, note *models.NoteAudio) error {
|
||||
audioRef := fmt.Sprintf("s3://%s/%s-normalized.m4a", bucket, note.UUID)
|
||||
audioFile := fmt.Sprintf("%s/user/%s-normalized.m4a", config.FilesDirectory, note.UUID)
|
||||
uploadPath := fmt.Sprintf("%s-normalized.m4a", note.UUID)
|
||||
|
||||
if !minioClient.ObjectExists(bucket, uploadPath) {
|
||||
err := minioClient.UploadFile(bucket, audioFile, uploadPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to upload audio: %v", err)
|
||||
}
|
||||
}
|
||||
var transcription = ""
|
||||
//if note.Transcription.IsValue() {
|
||||
//transcription = note.Transcription.MustGet()
|
||||
//}
|
||||
transcription = note.Transcription.GetOr("")
|
||||
simpleTasks := []map[string]interface{}{
|
||||
{
|
||||
"data": map[string]string{
|
||||
"audio": audioRef,
|
||||
"note_uuid": note.UUID.String(),
|
||||
"transcription": transcription,
|
||||
},
|
||||
"meta": map[string]string{
|
||||
"customer": customer,
|
||||
"note_uuid": note.UUID.String(),
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err := client.ImportTasks(project.ID, simpleTasks)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to import tasks: %v", err)
|
||||
}
|
||||
log.Printf("Created task for note audio %s", note.UUID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func findLabelStudioProject(client *labelstudio.Client, title string) (*labelstudio.Project, error) {
|
||||
// Attempt to get live projects
|
||||
projects, err := client.Projects()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get projects: %v", err)
|
||||
}
|
||||
fmt.Printf("Found %d projects:\n", projects.Count)
|
||||
for i, p := range projects.Results {
|
||||
fmt.Printf("%d. %s (ID: %d) - Tasks: %d\n",
|
||||
i+1,
|
||||
p.Title,
|
||||
p.ID,
|
||||
p.TaskNumber)
|
||||
if p.Title == title {
|
||||
return &p, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("No such project '%s'", title)
|
||||
}
|
||||
|
||||
func findMatchingTask(client *labelstudio.Client, project *labelstudio.Project, customer string, note *models.NoteAudio) (*labelstudio.Task, error) {
|
||||
/*meta := map[string]string{
|
||||
"customer": customer,
|
||||
"note_uuid": note.UUID,
|
||||
}*/
|
||||
items := []map[string]interface{}{
|
||||
{"filter": "filter:tasks:data.note_uuid", "operator": "equal", "type": "string", "value": note.UUID},
|
||||
}
|
||||
filters := map[string]interface{}{
|
||||
"conjunction": "and",
|
||||
"items": items,
|
||||
}
|
||||
query := map[string]interface{}{
|
||||
"filters": filters,
|
||||
}
|
||||
queryStr, err := json.Marshal(query)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to marshal query JSON: %v", err)
|
||||
}
|
||||
// Get all tasks
|
||||
options := &labelstudio.TasksListOptions{
|
||||
ProjectID: project.ID,
|
||||
Query: string(queryStr),
|
||||
}
|
||||
tasksResponse, err := client.ListTasks(options)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to get tasks: %v", err)
|
||||
}
|
||||
if len(tasksResponse.Tasks) == 0 {
|
||||
return nil, nil
|
||||
} else if len(tasksResponse.Tasks) == 1 {
|
||||
return &tasksResponse.Tasks[0], nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("Got too many tasks: %d", len(tasksResponse.Tasks))
|
||||
}
|
||||
// Specify bucket name
|
||||
//bucketNamePtr := flag.String("bucket", "label-studio", "The bucket to upload to")
|
||||
//filePathPtr := flag.String("file", "example.txt", "The file to upload")
|
||||
//flag.Parse()
|
||||
}
|
||||
|
|
|
|||
17
sync/text.go
17
sync/text.go
|
|
@ -1,17 +0,0 @@
|
|||
package sync
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
)
|
||||
|
||||
type contentTextMessages struct{}
|
||||
|
||||
func getTextMessages(ctx context.Context, r *http.Request, u platform.User) (*html.Response[contentTextMessages], *nhttp.ErrorWithStatus) {
|
||||
content := contentTextMessages{}
|
||||
return html.NewResponse("sync/text-messages.html", content), nil
|
||||
}
|
||||
54
sync/tile.go
54
sync/tile.go
|
|
@ -1,54 +0,0 @@
|
|||
package sync
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
)
|
||||
|
||||
func getTileGPS(w http.ResponseWriter, r *http.Request, u platform.User) {
|
||||
ctx := r.Context()
|
||||
if err := r.ParseForm(); err != nil {
|
||||
respondError(w, "Could not parse form", err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
lat_s := r.FormValue("lat")
|
||||
lng_s := r.FormValue("lng")
|
||||
level_s := r.FormValue("level")
|
||||
if lat_s == "" || lng_s == "" || level_s == "" {
|
||||
respondError(w, "you must specify lat, lng, and level", nil, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
level, err := strconv.Atoi(level_s)
|
||||
if err != nil {
|
||||
respondError(w, "couldn't parse level", err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
lat, err := strconv.ParseFloat(lat_s, 10)
|
||||
if err != nil {
|
||||
respondError(w, "couldn't parse lat", err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
lng, err := strconv.ParseFloat(lng_s, 10)
|
||||
if err != nil {
|
||||
respondError(w, "couldn't parse lng", err, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
img, err := platform.ImageAtPoint(ctx, u.Organization, uint(level), lat, lng)
|
||||
if err != nil {
|
||||
respondError(w, "image at point", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(img.Content)))
|
||||
_, err = io.Copy(w, bytes.NewBuffer(img.Content))
|
||||
if err != nil {
|
||||
respondError(w, "copy bytes", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue