models

package
v0.0.0-...-55b201a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// in meter
	RADIUS_DISTRIBUTION_CITY     float64 = 5000
	RADIUS_DISTRIBUTION_DISTRICT float64 = 3000
	RADIUS_DISTRIBUTION_VILLAGE  float64 = 1500
)

* Assumptions about distribute random places: * - Due unknown border locations, assume below constants * are a safe radius for distributing random places which * those places are still belong to such region we referred to, * Eventhough in real life, the provided location isn't centralized * against the shape as overall and has various distance to its border * Also some places discovered (not did much reasearches) have really short * distance to its border from its provided location (about < 1km)

View Source
const (
	VILLAGE_URL  string = "https://data.jabarprov.go.id/api-backend/bigdata/diskominfo/od_kode_wilayah_dan_nama_wilayah_desa_kelurahan?limit=5957"
	DISTRICT_URL string = "https://data.jabarprov.go.id/api-backend/bigdata/diskominfo/od_16357_kode_wilayah_dan_nama_wilayah_kecamatan?limit=627"
	CITY_URL     string = "https://data.jabarprov.go.id/api-backend/bigdata/diskominfo/od_kode_wilayah_dan_nama_wilayah_kota_kabupaten?limit=27"
)
View Source
const (
	LATITUDE_PER_METRE = 1 / (111.32 * 1000)
)

Assuming that the Earth is a sphere with a circumference of 40075 km. So, Length in meters of 1° of latitude = always 111.32 km Length in meters of 1° of longitude = 40075 km * cos( latitude ) / 360

Variables

View Source
var MapCategories = map[string][]Category{
	"city": {
		{ID: 1, Name: "Kantor Pemerintah", Count: 1},
		{ID: 2, Name: "Rumah Sakit", Count: 3},
		{ID: 3, Name: "SMA", Count: 20},
	},
	"district": {
		{ID: 4, Name: "Kantor Pemerintah Kecamatan", Count: 1},
		{ID: 5, Name: "Puskesmas", Count: 5},
		{ID: 6, Name: "SMP", Count: 3},
	},
	"village": {
		{ID: 7, Name: "Kantor Pemerintah", Count: 1},
		{ID: 8, Name: "Tempat Ibadah", Count: 20},
		{ID: 9, Name: "SD", Count: 5},
	},
}

Predefined categories, mapped by their region level ID 1-3 city level ID 4-6 district level ID 7-9 village level

Functions

func DegToRad

func DegToRad(deg float64) float64

converter utilities

func LONGITUDE_PER_METRE

func LONGITUDE_PER_METRE(l float64) float64

func MapAppend

func MapAppend[R Regionable](dataMap *map[string][]R, k string, data R)

Using generic, check if key exists of a region structs, append to value which is a slice If doesn't extist, initialize the new one

func RadToDeg

func RadToDeg(rad float64) float64

func RequestThenUnmarshall

func RequestThenUnmarshall[R Unmarshallable](url string, data *R) error

Using generic, request to the given URL and unmarshalling to data which R type.

Types

type BatchData

type BatchData struct {
	Cities    []City
	NCity     uint
	NDistrict uint
	NVillage  uint
}

structuring unmarshalled json from API call

func LoadAll

func LoadAll() BatchData

Load all data and seed to defined structs

type BatchPlace

type BatchPlace struct {
	CityPlaces []CityPlace
}

func GeneratePlaces

func GeneratePlaces(data BatchData) BatchPlace

type Category

type Category struct {
	ID    uint8
	Name  string
	Count uint
}

type City

type City struct {
	CoreInfo  CoreInfo
	Districts []District
}

structuring unmarshalled json from API call

type CityPlace

type CityPlace struct {
	Location Location
	Name     string  // for debuggin purposes
	Places   []Place // all places in a city
}

type CityRequest

type CityRequest struct {
	Name      string `json:"kemendagri_kota_nama" validate:"required"`
	Level     string
	Code      float64 `json:"kemendagri_kota_kode" validate:"required"`
	Latitude  float64 `json:"latitude" validate:"required"`
	Longitude float64 `json:"longitude" validate:"required"`
}

type CoreInfo

type CoreInfo struct {
	Location Location
	Level    string
	Name     string
	Code     string
}

common attributes / structures

type DataCityReq

type DataCityReq struct {
	Data []CityRequest `json:"data" validate:"required"`
}

type DataDistrictReq

type DataDistrictReq struct {
	Data []DistrictRequest `json:"data" validate:"required"`
}

type DataVillageReq

type DataVillageReq struct {
	Data []VillageRequest `json:"data" validate:"required"`
}

need to be seperated due different JSON struct tag

type DirectionH

type DirectionH int
const (
	East DirectionH = 1
	West DirectionH = 2
)

horizontal shift toward DirectionH constants (east or west) means longitude increased or decreased but latitude remains the same

type DirectionV

type DirectionV int
const (
	North DirectionV = 1
	South DirectionV = 2
)

vertical shift toward DirectionV constants (south or north) means latitude increased or decreased but longitude remains the same

type District

type District struct {
	CoreInfo CoreInfo
	Villages []Village
}

structuring unmarshalled json from API call

type DistrictRequest

type DistrictRequest struct {
	Name      string `json:"kemendagri_kecamatan_nama" validate:"required"`
	Level     string
	Code      string  `json:"kemendagri_kecamatan_kode" validate:"required"`
	Latitude  float64 `json:"latitude" validate:"required"`
	Longitude float64 `json:"longitude" validate:"required"`
}

type Location

type Location struct {
	Latitude  float64
	Longitude float64
}

common attributes / structures

func RandShiftLoc

func RandShiftLoc(l Location, dist float64) Location

Perform diagonal shift randomly from given location

func ShiftLoc

func ShiftLoc(l Location, dist float64, dv DirectionV, dh DirectionH) Location

pure function, returning new object location based given direction and distance

type Place

type Place struct {
	ID           uint8   `json:"id"` // refers to building ownership in region
	CityName     string  `json:"city_name"`
	DistrictName string  `json:"district_name,omitempty"`
	VillageName  string  `json:"village_name,omitempty"`
	CategoryID   uint8   `json:"category_id"`
	Name         string  `json:"name"`
	Longitude    float64 `json:"longitude"`
	Latitude     float64 `json:"latitude"`
}

Struct for response [GET] /search

func GetNearbyPlaces

func GetNearbyPlaces(q WebQuery, bp BatchPlace) ([]Place, error)

assumption: the pinned location cant be surrounded by more than five cities. only scan places in closest cities.

type Regionable

type Regionable interface {
	Village | District | City
}

define region type, used in mapping

type Unmarshallable

type Unmarshallable interface {
	DataVillageReq | DataDistrictReq | DataCityReq
}

unmarshallable define type that would satisfy to unmarshall byte data from API

type Village

type Village struct {
	CoreInfo CoreInfo
}

structuring unmarshalled json from API call

type VillageRequest

type VillageRequest struct {
	Name      string `json:"kemendagri_kelurahan_nama" validate:"required"`
	Level     string
	Code      string  `json:"kemendagri_kelurahan_kode" validate:"required"`
	Latitude  float64 `json:"latitude" validate:"required"`
	Longitude float64 `json:"longitude" validate:"required"`
}

type WebQuery

type WebQuery struct {
	Latitude   float64
	Longitude  float64
	CategoryId uint8
}

Struct for request [GET] /search

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL