Commit a7f9d4f3 authored by Ikram Haq's avatar Ikram Haq
Browse files

Fix issue related to address query parameter and relative_location_info

parent 7223812a
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package sbi

import (
	"errors"
	"math"
	"strings"
	"sync"
	"time"
@@ -37,7 +36,7 @@ type SbiCfg struct {
	MepName        string
	RedisAddr      string
	Locality       []string
	UserInfoCb     func(string, string, string, *float32, *float32, *string, *string, *float64, *float64, *float32, *float32)
	UserInfoCb     func(string, string, string, *float32, *float32, *string, *string, *float32, *float32, *float32, *float32)
	ZoneInfoCb     func(string, int, int, int)
	ApInfoCb       func(string, string, string, string, int, *float32, *float32)
	ScenarioNameCb func(string)
@@ -56,7 +55,7 @@ type LocServSbi struct {
	activeModel             *mod.Model
	gisCache                *gc.GisCache
	refreshTicker           *time.Ticker
	updateUserInfoCB        func(string, string, string, *float32, *float32, *string, *string, *float64, *float64, *float32, *float32)
	updateUserInfoCB        func(string, string, string, *float32, *float32, *string, *string, *float32, *float32, *float32, *float32)
	updateZoneInfoCB        func(string, int, int, int)
	updateAccessPointInfoCB func(string, string, string, string, int, *float32, *float32)
	updateScenarioNameCB    func(string)
@@ -311,8 +310,8 @@ func processActiveScenarioUpdate() {
		}
		// Convert user's geographic coordinates to Cartesian coordinates relative to the origin
		x, y := geographicToCartesian(latitude, longitude, originLatitude, originLongitude)
		var X *float64 = &x
		var Y *float64 = &y
		var X *float32 = &x
		var Y *float32 = &y
		sbi.updateUserInfoCB(name, zone, netLoc, longitude, latitude, country_name, mapid, X, Y, originLatitude, originLongitude)
		uePerZoneMap[zone]++
		uePerNetLocMap[netLoc]++
@@ -383,23 +382,24 @@ func processActiveScenarioUpdate() {
	}
}

func geographicToCartesian(userLatitude, userLongitude, originLatitude, originLongitude *float32) (x, y float64) {
const Pi float32 = 3.14159265358979323846264338327950288419716939937510582097494459 // 3.14159
func geographicToCartesian(userLatitude, userLongitude, originLatitude, originLongitude *float32) (x, y float32) {
	// Earth's radius in meters
	const R = 6371000.0
	const R float32 = 6371000.0

	// Convert user's latitude and longitude from degrees to radians
	userLatRad := float64(*userLatitude) * (math.Pi / 180.0)
	userLonRad := float64(*userLongitude) * (math.Pi / 180.0)
	userLatRad := *userLatitude * (Pi / 180.0)
	userLonRad := *userLongitude * (Pi / 180.0)

	// Convert origin latitude and longitude from degrees to radians
	originLatRad := float64(*originLatitude) * (math.Pi / 180.0)
	originLonRad := float64(*originLongitude) * (math.Pi / 180.0)
	originLatRad := *originLatitude * (Pi / 180.0)
	originLonRad := *originLongitude * (Pi / 180.0)

	// Calculate X coordinate relative to the origin
	x = R * (userLonRad - originLonRad)
	// Calculate X coordinate relative to the origin (northing)
	x = R * (userLatRad - originLatRad)

	// Calculate Y coordinate relative to the origin (using Mercator projection formula)
	y = R*math.Log(math.Tan((math.Pi/4)+(userLatRad/2))) - R*math.Log(math.Tan((math.Pi/4)+(originLatRad/2)))
	// Calculate Y coordinate relative to the origin (easting)
	y = R * (userLonRad - originLonRad)

	return x, y
}
@@ -459,8 +459,8 @@ func refreshPositions() {
			continue
		}
		x, y := geographicToCartesian(latitude, longitude, originLatitude, originLongitude)
		var X *float64 = &x
		var Y *float64 = &y
		var X *float32 = &x
		var Y *float32 = &y
		sbi.updateUserInfoCB(name, zone, netLoc, longitude, latitude, country_name, mapid, X, Y, originLatitude, originLongitude)
	}

+9 −5
Original line number Diff line number Diff line
@@ -1786,11 +1786,15 @@ func usersGet(w http.ResponseWriter, r *http.Request) {
	userList.ResourceURL = hostUrl.String() + basePath + "queries/users"
	response.UserList = &userList
	userData.userList = &userList
	// Check if "address" parameter exists
	if _, ok := q["address"]; ok {
		// Execute the code block only if "address" parameter is given
		jsonUserInfo, _ := rc.JSONGetEntry(baseKey+typeUser+":"+q.Get("address"), ".")
		if jsonUserInfo == "" {
			w.WriteHeader(http.StatusNotFound)
			return
		}
	}

	keyName := baseKey + typeUser + ":*"
	err := rc.ForEachJSONEntry(keyName, populateUserList, &userData)
@@ -3941,7 +3945,7 @@ func updateStoreName(storeName string) {
	}
}

func updateUserInfo(address string, zoneId string, accessPointId string, longitude *float32, latitude *float32, country *string, mapid *string, x *float64, y *float64, originLatitude *float32, originLongitude *float32) {
func updateUserInfo(address string, zoneId string, accessPointId string, longitude *float32, latitude *float32, country *string, mapid *string, x *float32, y *float32, originLatitude *float32, originLongitude *float32) {
	var oldZoneId string
	var oldApId string

+2 −2
Original line number Diff line number Diff line
@@ -11,9 +11,9 @@ package server

type RelativeLocationInfo struct {
	// Indicates the value (in the unit of meters) on x-axis of the relative location in the Cartesian system. Positive value represents easting from origin.
	X float64 `json:"X"`
	X float32 `json:"X"`
	// Indicates the value (in the unit of meters) on y-axis of the relative location in the Cartesian system. Positive value represents northing from origin.
	Y float64 `json:"Y"`
	Y float32 `json:"Y"`
	// Indicates the value (in the unit of meters) on z-axis of the relative location in the Cartesian system for a 3DPoint. Positive value represents height above origin.
	Z float32 `json:"Z,omitempty"`