hanapi

package
v0.0.0-...-5f1e064 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const RecencyBias = 350

RecencyBias is a multiplier used to create a more equal weighting between recency and distance

View Source
const RegionSize = 5000

RegionSize is radius of a region in meters

Variables

This section is empty.

Functions

func AddRegion

func AddRegion(db DatabaseInterface, lat float64, lng float64)

AddRegion - adds a new region for image population

func ContainsRegion

func ContainsRegion(db DatabaseInterface, lat float64, lng float64) bool

ContainsRegion - determines whether a point is within a specific region

func ReportImage

func ReportImage(db DatabaseInterface, id string, reason string,
	logger reporting.Logger)

ReportImage - report an image to be removed @param id - the image ID which should match one in ImageData @param reason - reason for reporting @param logger - optional logging functionality

Types

type BySum

type BySum []ImageData

BySum is a sorting heuristic based on distance and recency

func (BySum) Len

func (images BySum) Len() int

func (BySum) Less

func (images BySum) Less(i, j int) bool

func (BySum) Swap

func (images BySum) Swap(i, j int)

type DatabaseInterface

type DatabaseInterface interface {
	GetRegions() []Location
	AddRegion(lat float64, lng float64)
	AddImage(image ImageData)
	AddBulkImagesToRegion(images []ImageData, region *Location)
	GetImages(lat float64, lng float64, start int, end int) []ImageData
	GetAllImages() []ImageData
	SoftDelete(id string, reason string)
	DeleteOldImages(amount int)
	Size() int
	Copy() DatabaseInterface
	Close()
}

DatabaseInterface - a generic interface for database queries

func NewMongoInterface

func NewMongoInterface() DatabaseInterface

NewMongoInterface - use to create a new mongo connection

type ImageData

type ImageData struct {
	Caption      string    `json:"caption" bson:"caption"`
	CreatedTime  int64     `json:"createdTime" bson:"createdTime"`
	ImageURL     string    `json:"url" bson:"url"`
	Link         string    `json:"link" bson:"link"`
	User         *User     `json:"user" bson:"user"`
	ThumbnailURL string    `json:"thumbnail_url" bson:"thumbnail_url"`
	ID           string    `json:"id" bson:"_id"`
	Location     *Location `json:"location" bson:"location"`
	// regions are specified imageops.go
	Region *Location `json:"region" bson:"region"`
	// where the photo was taken
	Coordinates []float64 `json:"coordinates" bson:"coordinates"`
	// will be set when querying using DatabaseInterface
	Distance float64 `json:"distance" bson:"distance"`
	// the source of the image
	Source string `json:"source" bson:"source"`
}

ImageData is data that is stored and returned from `hanapi`

func GetImages

func GetImages(db DatabaseInterface, lat float64, lng float64) []ImageData

GetImages - get images near the location sorted by distance and recency

func GetImagesWithEnd

func GetImagesWithEnd(db DatabaseInterface, lat float64, lng float64,
	end int) []ImageData

GetImagesWithEnd - get images from the beginning to the specified end

func GetImagesWithRange

func GetImagesWithRange(db DatabaseInterface, lat float64, lng float64,
	start int, end int) []ImageData

GetImagesWithRange - Specify a range, so that you can query a portion of the image list @param start - start is optional, use -1 to signify no value, indexing starts at zero @param end - end is optional, use -1 to signify no value

func GetImagesWithStart

func GetImagesWithStart(db DatabaseInterface, lat float64, lng float64,
	start int) []ImageData

GetImagesWithStart - get images starting at a certain point

func NewImage

func NewImage(caption string, createdTime int64, imageURL string,
	thumbnailURL string, id string, lat float64, lng float64, link string,
	user string, profilePictureURL string, source string) *ImageData

NewImage returns a new image that's suitable for being added to the database. Note that region is not specified here, this is done before entry into the database. This is because the collectors have no real idea of which query belongs to which region

func NewImageWithDistance

func NewImageWithDistance(caption string, createdTime int64, imageURL string,
	thumbnailURL string, id string, lat float64, lng float64, distance float64) *ImageData

NewImageWithDistance returns a new image with distance specified Created purely for testing purposes, so that the distance can be specified

type Location

type Location struct {
	Lat float64 `json:"lat" bson:"lat"`
	Lng float64 `json:"lng" bson:"lng"`
}

Location is a type which contains the lat and lng

func GetRegion

func GetRegion(db DatabaseInterface, lat float64, lng float64) *Location

GetRegion - returns the region which the specified lat, lng lies in

func GetRegions

func GetRegions(db DatabaseInterface) []Location

GetRegions - returns the currently used regions

func NewLocation

func NewLocation(lat float64, lng float64) *Location

NewLocation returns a new location

type MongoInterface

type MongoInterface struct {
	DatabaseInterface
	// contains filtered or unexported fields
}

MongoInterface - a mongodb implementation of `DatabaseInterface`

func (*MongoInterface) AddBulkImagesToRegion

func (c *MongoInterface) AddBulkImagesToRegion(images []ImageData,
	region *Location)

AddBulkImagesToRegion adds new images in bulk, also setting the region

func (*MongoInterface) AddImage

func (c *MongoInterface) AddImage(image ImageData)

AddImage adds new image data for the feed

func (*MongoInterface) AddRegion

func (c *MongoInterface) AddRegion(lat float64, lng float64)

AddRegion adds this new location as a place to query images on

func (*MongoInterface) Close

func (c *MongoInterface) Close()

Close will close the current mongo connection

func (*MongoInterface) Copy

Copy the interface for added concurrency

func (*MongoInterface) DeleteOldImages

func (c *MongoInterface) DeleteOldImages(amount int)

DeleteOldImages will clear `amount` worth of images starting at the oldest

func (*MongoInterface) GetAllImages

func (c *MongoInterface) GetAllImages() []ImageData

GetAllImages returns all images stored

func (*MongoInterface) GetImages

func (c *MongoInterface) GetImages(lat float64, lng float64, start int, end int) []ImageData

GetImages returns images closest to the specified location

func (*MongoInterface) GetRegions

func (c *MongoInterface) GetRegions() []Location

GetRegions returns the watched locations that are stored in the database These locations are queried to populate the database with images

func (*MongoInterface) Size

func (c *MongoInterface) Size() int

Size will return the amount of images in the database

func (*MongoInterface) SoftDelete

func (c *MongoInterface) SoftDelete(id string, reason string)

SoftDelete will add a delete field to image so it's no longer visible in feed

type User

type User struct {
	Username          string `json:"username" bson:"username"`
	ProfilePictureURL string `json:"profile_picture" bson:"profile_picture"`
}

User is a type used to keep track of the source of an image

func NewUser

func NewUser(username string, profileURL string) *User

NewUser returns new user

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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