ct

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplicationJSONFilename = "us_ct_applications.json"
	ApplicationCSVFilename  = "us_ct_applications.csv"
	ApplicationsURL         = "https://data.ct.gov/resource/bqby-dyzr.json"
)
View Source
const (
	BrandJSONFilename = "us_ct_brands.json"
	BrandCSVFilename  = "us_ct_brands.csv"
	// BrandsURL is the URL to fetch the CT cannabis brands data
	BrandsURL = "https://data.ct.gov/resource/egd5-wb6r.json"
)
View Source
const (
	CredentialJSONFilename = "us_ct_credentials.json"
	CredentialCSVFilename  = "us_ct_credentials.csv"
	CredentialsURL         = "https://data.ct.gov/resource/tjfe-s2x9.json"
)
View Source
const (
	LotteryJSONFilename = "us_ct_lottery.json"
	LotteryCSVFilename  = "us_ct_lottery.csv"
	LotteryURL          = "https://data.ct.gov/resource/w85q-8cfm.json"
)
View Source
const (
	RetailLocationJSONFilename = "us_ct_retail_locations.json"
	RetailLocationCSVFilename  = "us_ct_retail_locations.csv"
	RetailLocationsURL         = "https://data.ct.gov/resource/42yd-3x3d.json"
)
View Source
const (
	WeeklySalesJSONFilename = "us_ct_weekly_sales.json"
	WeeklySalesCSVFilename  = "us_ct_weekly_sales.csv"
	WeeklySalesURL          = "https://data.ct.gov/resource/ucaf-96h6.json"
)
View Source
const (
	TaxJSONFilename = "us_ct_tax.json"
	TaxCSVFilename  = "us_ct_tax.csv"
	TaxURL          = "https://data.ct.gov/resource/jey2-vq68.json"
)
View Source
const (
	ZoningJSONFilename = "us_ct_zoning.json"
	ZoningCSVFilename  = "us_ct_zoning.csv"
	ZoningURL          = "https://data.ct.gov/resource/khc7-gd9u.json"
)

Variables

View Source
var ApplicationConfig = sources.SocrataConfig{
	URL:           ApplicationsURL,
	CacheFilename: ApplicationJSONFilename,
}

ApplicationConfig returns the Socrata configuration for applications

View Source
var BrandConfig = sources.SocrataConfig{
	URL:           BrandsURL,
	CacheFilename: BrandJSONFilename,
	OrderBy:       "registration_number",
}

BrandConfig is the Socrata configuration for fetching brands

View Source
var CredentialConfig = sources.SocrataConfig{
	URL:           CredentialsURL,
	CacheFilename: CredentialJSONFilename,
}

CredentialConfig returns the Socrata configuration for credentials

View Source
var DuckDBMigration string
View Source
var LotteryConfig = sources.SocrataConfig{
	URL:           LotteryURL,
	CacheFilename: LotteryJSONFilename,
	OrderBy:       "credential_type",
}

LotteryConfig returns the Socrata configuration for lottery

View Source
var RetailLocationConfig = sources.SocrataConfig{
	URL:           RetailLocationsURL,
	CacheFilename: RetailLocationJSONFilename,
	OrderBy:       "license",
}

RetailLocationConfig returns the Socrata configuration for retail locations

View Source
var TaxConfig = sources.SocrataConfig{
	URL:           TaxURL,
	CacheFilename: TaxJSONFilename,
	OrderBy:       "period_end_date",
}

TaxConfig returns the Socrata configuration for tax data

View Source
var WeeklySalesConfig = sources.SocrataConfig{
	URL:           WeeklySalesURL,
	CacheFilename: WeeklySalesJSONFilename,
	OrderBy:       "unnamed_column",
}

WeeklySalesConfig returns the Socrata configuration for weekly sales

View Source
var ZoningConfig = sources.SocrataConfig{
	URL:           ZoningURL,
	CacheFilename: ZoningJSONFilename,
	OrderBy:       "town",
}

ZoningConfig returns the Socrata configuration for zoning

Functions

func CSVString

func CSVString(str string) string

CSVString sanitizes a string for use in a CSV file field

func DBInsertApplications

func DBInsertApplications(conn *sql.DB, applications []Application) error

DBInsertApplications inserts applications into DuckDB

func DBInsertBrands

func DBInsertBrands(conn *sql.DB, brands []Brand) error

func DBInsertCredentials

func DBInsertCredentials(conn *sql.DB, credentials []Credential) error

DBInsertCredentials inserts credentials into DuckDB

func DBInsertLottery added in v0.2.0

func DBInsertLottery(conn *sql.DB, lottery []Lottery) error

DBInsertLottery inserts lottery records into DuckDB

func DBInsertRetailLocations added in v0.2.0

func DBInsertRetailLocations(conn *sql.DB, locations []RetailLocation) error

DBInsertRetailLocations inserts retail locations into DuckDB

func DBInsertTax

func DBInsertTax(conn *sql.DB, taxes []Tax) error

DBInsertTax inserts tax records into DuckDB

func DBInsertWeeklySales

func DBInsertWeeklySales(conn *sql.DB, sales []WeeklySales) error

DBInsertWeeklySales inserts weekly sales into DuckDB

func DBInsertZoning added in v0.2.0

func DBInsertZoning(conn *sql.DB, zoning []Zoning) error

DBInsertZoning inserts zoning records into DuckDB

func IsBrandErroneous

func IsBrandErroneous(b *Brand) bool

IsBrandErroneous checks if the brand is erroneous

func IsEmptyMeasurement

func IsEmptyMeasurement(str string) bool

IsEmptyMeasurement returns true if the string is considered an empty measure Examples are: "" and "."

func IsErrorMeasurement

func IsErrorMeasurement(str string) bool

IsErrorMeasurement returns true if the string is considered to be erroneous

func IsTraceMeasurement

func IsTraceMeasurement(str string) bool

IsTraceMeasurement returns true if the string is considered a trace measure Examples are: "TRC" "<LOQ" and "<0.1"

Types

type Application

type Application struct {
	ApplicationLicenseNumber    string              `json:"application_license_number"`
	ApplicationCredentialStatus string              `json:"application_credential_status"`
	StatusReason                string              `json:"status_reason"`
	SECReviewStatus             string              `json:"sec_review_status"`
	InitialApplicationType      string              `json:"initial_application_type"`
	HowSelected                 string              `json:"how_selected"`
	Name                        string              `json:"name"`
	Documents                   ApplicationDocument `json:"documents"`
}

Application represents a CT cannabis license application

func FetchApplications

func FetchApplications(appToken string, maxCacheAge time.Duration) ([]Application, error)

FetchApplications fetches all CT cannabis application data from the CT API

func (Application) CSVHeaders

func (a Application) CSVHeaders() string

CSVHeaders returns the CSV headers for the Application struct

func (Application) CSVValue

func (a Application) CSVValue() string

CSVValue returns the CSV value for the Application struct

type ApplicationDocument

type ApplicationDocument struct {
	URL string `json:"url"`
}

ApplicationDocument represents a document attached to an application

type Brand

type Brand struct {
	BrandName                    string       `csv:"BRAND-NAME" json:"brand_name"`
	DosageForm                   string       `csv:"DOSAGE-FORM" json:"dosage_form"`
	Producer                     string       `csv:"PRODUCER" json:"producer"`
	ProductImage                 Image        `csv:"PRODUCT-IMAGE" json:"product_image"`
	LabelImage                   Image        `csv:"LABEL-IMAGE" json:"label_image"`
	LabAnalysis                  Image        `csv:"LAB-ANALYSIS" json:"lab_analysis"`
	ApprovalDate                 iso8601.Time `csv:"APPROVAL-DATE" json:"approval_date"`
	RegistrationNumber           string       `csv:"REGISTRATION-NUMBER" json:"registration_number"`
	TetrahydrocannabinolThc      Measure      `csv:"TETRAHYDROCANNABINOL-THC" json:"tetrahydrocannabinol_thc"`
	TetrahydrocannabinolAcidThca Measure      `csv:"TETRAHYDROCANNABINOL-ACID-THCA" json:"tetrahydrocannabinol_acid_thca"`
	CannabidiolsCbd              Measure      `csv:"CANNABIDIOLS-CBD" json:"cannabidiols_cbd"`
	CannabidiolAcidCbda          Measure      `csv:"CANNABIDIOL-ACID-CBDA" json:"cannabidiol_acid_cbda"`
	APinene                      Measure      `csv:"A-PINENE" json:"a_pinene"`
	BMyrcene                     Measure      `csv:"B-MYRCENE" json:"b_myrcene"`
	BCaryophyllene               Measure      `csv:"B-CARYOPHYLLENE" json:"b_caryophyllene"`
	BPinene                      Measure      `csv:"B-PINENE" json:"b_pinene"`
	Limonene                     Measure      `csv:"LIMONENE" json:"limonene"`
	Ocimene                      Measure      `csv:"OCIMENE" json:"ocimene"`
	LinaloolLin                  Measure      `csv:"LINALOOL-LIN" json:"linalool_lin"`
	HumuleneHum                  Measure      `csv:"HUMULENE-HUM" json:"humulene_hum"`
	Cbg                          Measure      `csv:"CBG" json:"cbg"`
	CbgA                         Measure      `csv:"CBG-A" json:"cbg_a"`
	CannabavarinCbdv             Measure      `csv:"CANNABAVARIN-CBDV" json:"cannabavarin_cbdv"`
	CannabichromeneCbc           Measure      `csv:"CANNABICHROMENE-CBC" json:"cannabichromene_cbc"`
	CannbinolCbn                 Measure      `csv:"CANNBINO-CBN" json:"cannbinol_cbn"`
	TetrahydrocannabivarinThcv   Measure      `csv:"TETRAHYDROCANNABIVARIN-THCV" json:"tetrahydrocannabivarin_thcv"`
	ABisabolol                   Measure      `csv:"A-BISABOLOL" json:"a_bisabolol"`
	APhellandrene                Measure      `csv:"A-PHELLANDRENE" json:"a_phellandrene"`
	ATerpinene                   Measure      `csv:"A-TERPINENE" json:"a_terpinene"`
	BEudesmol                    Measure      `csv:"B-EUDESMOL" json:"b_eudesmol"`
	BTerpinene                   Measure      `csv:"B-TERPINENE" json:"b_terpinene"`
	Fenchone                     Measure      `csv:"FENCHONE" json:"fenchone"`
	Pulegol                      Measure      `csv:"PULEGOL" json:"pulegol"`
	Borneol                      Measure      `csv:"BORNEOL" json:"borneol"`
	Isopulegol                   Measure      `csv:"ISOPULEGOL" json:"isopulegol"`
	Carene                       Measure      `csv:"CARENE" json:"carene"`
	Camphene                     Measure      `csv:"CAMPHENE" json:"camphene"`
	Camphor                      Measure      `csv:"CAMPHOR" json:"camphor"`
	CaryophylleneOxide           Measure      `csv:"CARYOPHYLLENE_OXIDE" json:"caryophyllene_oxide"`
	Cedrol                       Measure      `csv:"CEDROL" json:"cedrol"`
	Eucalyptol                   Measure      `csv:"EUCALYPTOL" json:"eucalyptol"`
	Geraniol                     Measure      `csv:"GERANIOL" json:"geraniol"`
	Guaiol                       Measure      `csv:"GUAIOL" json:"guaiol"`
	GeranylAcetate               Measure      `csv:"GERANYL_ACETATE" json:"geranyl_acetate"`
	Isoborneol                   Measure      `csv:"ISOBORNEOL" json:"isoborneol"`
	Menthol                      Measure      `csv:"MENTHOL" json:"menthol"`
	LFenchone                    Measure      `csv:"L-FENCHONE" json:"l_fenchone"`
	Nerol                        Measure      `csv:"NEROL" json:"nerol"`
	Sabinene                     Measure      `csv:"SABINENE" json:"sabinene"`
	Terpineol                    Measure      `csv:"TERPINEOL" json:"terpineol"`
	Terpinolene                  Measure      `csv:"TERPINOLENE" json:"terpinolene"`
	TransBFarnesene              Measure      `csv:"TRANS-B-FARNESENE" json:"trans_b_farnesene"`
	Valencene                    Measure      `csv:"VALENCENE" json:"valencene"`
	ACedrene                     Measure      `csv:"A-CEDRENE" json:"a_cedrene"`
	AFarnesene                   Measure      `csv:"A-FARNESENE" json:"a_farnesene"`
	BFarnesene                   Measure      `csv:"B-FARNESENE" json:"b_farnesene"`
	CisNerolidol                 Measure      `csv:"CIS-NEROLIDOL" json:"cis_nerolidol"`
	Fenchol                      Measure      `csv:"FENCHOL" json:"fenchol"`
	TransNerolidol               Measure      `csv:"TRANS-NEROLIDOL" json:"trans_nerolidol"`
	Market                       string       `csv:"Market" json:"market"`
	Chemotype                    string       `csv:"Chemotype" json:"chemotype"`
	ProcessingTechnique          string       `csv:"Processing Technique" json:"processing_technique"`
	SolventsUsed                 string       `csv:"Solvents Used" json:"solvents_used"`
	NationalDrugCode             string       `csv:"National Drug Code" json:"national_drug_code"`
}

Brand represents a raw Cannabis Brand Record from CT

func CleanBrands

func CleanBrands(bs []Brand) []Brand

CleanBrands filters out bad Brand samples using IsBrandErroneous().

func FetchBrands

func FetchBrands(appToken string, maxCacheAge time.Duration) ([]Brand, error)

FetchBrands fetches all the CT cannabis brands data from the CT API

func (Brand) CSVHeaders

func (b Brand) CSVHeaders() string

CSVHeaders returns the CSV headers for the Brand struct

func (Brand) CSVValue

func (b Brand) CSVValue() string

CSVValue returns the CSV value for the Brand struct

type Credential

type Credential struct {
	CredentialType string `json:"credentialtype"`
	Status         string `json:"status"`
	Count          string `json:"count"`
}

Credential represents a CT cannabis credential count record

func FetchCredentials

func FetchCredentials(appToken string, maxCacheAge time.Duration) ([]Credential, error)

FetchCredentials fetches all CT cannabis credential data from the CT API

func (Credential) CSVHeaders

func (c Credential) CSVHeaders() string

CSVHeaders returns the CSV headers for the Credential struct

func (Credential) CSVValue

func (c Credential) CSVValue() string

CSVValue returns the CSV value for the Credential struct

func (Credential) CountInt

func (c Credential) CountInt() int

CountInt returns the count as an integer

type Image

type Image struct {
	URL         string `csv:"url" json:"url"`
	Description string `csv:"desc" json:"description"`
}

type Lottery added in v0.2.0

type Lottery struct {
	CredentialType             string `json:"credential_type"`
	SocialEquityCouncilLottery string `json:"social_equity_council_lottery"`
	GeneralLottery             string `json:"general_lottery"`
}

Lottery represents a CT cannabis lottery report row

func FetchLottery added in v0.2.0

func FetchLottery(appToken string, maxCacheAge time.Duration) ([]Lottery, error)

FetchLottery fetches all CT cannabis lottery data from the CT API

func (Lottery) CSVHeaders added in v0.2.0

func (l Lottery) CSVHeaders() string

CSVHeaders returns the CSV headers for the Lottery struct

func (Lottery) CSVValue added in v0.2.0

func (l Lottery) CSVValue() string

CSVValue returns the CSV value for the Lottery struct

func (Lottery) GeneralLotteryInt added in v0.2.0

func (l Lottery) GeneralLotteryInt() int

GeneralLotteryInt returns the general lottery count as an integer

func (Lottery) SocialEquityCouncilLotteryInt added in v0.2.0

func (l Lottery) SocialEquityCouncilLotteryInt() int

SocialEquityCouncilLotteryInt returns the social equity lottery count as an integer

type Measure

type Measure struct {
	// contains filtered or unexported fields
}

Measure tracks a measurement, with special flags for no-measurement and trace measurement

func NewEmptyMeasure

func NewEmptyMeasure() Measure

NewEmptyMeasure creates a new "empty" measure. This may also be created through nil-initialization Measure{}

func NewMeasure

func NewMeasure(amount float64) Measure

NewMeasure creates a new measure with the given amount. Any amount < 0, will be treated as a trace measurement. To create an "empty" Measure object, use nil-initialization Measure{} or NewEmptyMeasure

func NewTraceMeasure

func NewTraceMeasure() Measure

NewTraceMeasure creates a new "trace amount" measure.

func (Measure) Amount

func (m Measure) Amount() (result float64, trace bool, empty bool)

Amount returns the value, isTrace, isEmpty

func (Measure) AsCSV

func (m Measure) AsCSV() string

AsCSV converts the measure to "" or "<amount>".

func (Measure) AsSQL

func (m Measure) AsSQL() string

AsSQL converts the measure to "NULL" or "<amount>".

func (*Measure) FromString

func (m *Measure) FromString(str string) error

FromString modifies the given measure based on the passed string

func (Measure) IsEmpty

func (m Measure) IsEmpty() bool

IsEmpty returns true if the measure is empty (no measurement)

func (Measure) IsTrace

func (m Measure) IsTrace() bool

IsTrace returns true if the measure is a trace amount

func (Measure) IsValidPercent

func (m Measure) IsValidPercent() bool

IsValidPercent returns true if the measure is a valid percentage (0-100)

func (Measure) IsZero

func (m Measure) IsZero() bool

IsZero returns true if the measure has an initialized, but zero value

func (Measure) MarshalCSV

func (m Measure) MarshalCSV() (string, error)

MarshalCSV marshals the measure to a CSV string

func (*Measure) MarshalJSON

func (m *Measure) MarshalJSON() ([]byte, error)

MarshalJSON converts the measure to JSON

func (*Measure) UnmarshalCSV

func (m *Measure) UnmarshalCSV(value string) error

UnmarshalCSV unmarshals the measure from a CSV string

func (*Measure) UnmarshalJSON

func (m *Measure) UnmarshalJSON(b []byte) error

UnmarshalJSON converts the measure from JSON

func (Measure) Value

func (m Measure) Value() (driver.Value, error)

Value implements the driver.Valuer interface for inserting into SQL

type RetailLocation added in v0.2.0

type RetailLocation struct {
	Type     string               `json:"type"`
	Business string               `json:"business"`
	DBA      string               `json:"dba"`
	License  string               `json:"license"`
	Street   string               `json:"street"`
	City     string               `json:"city"`
	Zipcode  string               `json:"zipcode"`
	Website  *RetailWebsite       `json:"website,omitempty"`
	Location *RetailLocationPoint `json:"location,omitempty"`
}

RetailLocation represents a CT licensed cannabis/medical marijuana retail location

func FetchRetailLocations added in v0.2.0

func FetchRetailLocations(appToken string, maxCacheAge time.Duration) ([]RetailLocation, error)

FetchRetailLocations fetches all CT retail location data from the CT API

func (RetailLocation) CSVHeaders added in v0.2.0

func (r RetailLocation) CSVHeaders() string

CSVHeaders returns the CSV headers for the RetailLocation struct

func (RetailLocation) CSVValue added in v0.2.0

func (r RetailLocation) CSVValue() string

CSVValue returns the CSV value for the RetailLocation struct

func (RetailLocation) HasLocation added in v0.2.0

func (r RetailLocation) HasLocation() bool

HasLocation reports whether this record has valid coordinates

func (RetailLocation) Latitude added in v0.2.0

func (r RetailLocation) Latitude() float64

Latitude returns the latitude or 0 if absent

func (RetailLocation) Longitude added in v0.2.0

func (r RetailLocation) Longitude() float64

Longitude returns the longitude or 0 if absent

func (RetailLocation) WebsiteURL added in v0.2.0

func (r RetailLocation) WebsiteURL() string

WebsiteURL returns the website URL or empty string if absent

type RetailLocationPoint added in v0.2.0

type RetailLocationPoint struct {
	Type        string    `json:"type"`
	Coordinates []float64 `json:"coordinates"`
}

RetailLocationPoint is a GeoJSON Point; Coordinates is [longitude, latitude]

type RetailWebsite added in v0.2.0

type RetailWebsite struct {
	URL string `json:"url"`
}

RetailWebsite is the nested website object from the Socrata dataset

type Tax

type Tax struct {
	PeriodEndDate     string `json:"period_end_date"` // ISO 8601 datetime
	Month             string `json:"month"`
	Year              string `json:"year"`
	FiscalYear        string `json:"fiscal_year"`
	PlantMaterialTax  string `json:"plant_material_tax"`
	EdibleProductsTax string `json:"edible_products_tax"`
	OtherCannabisTax  string `json:"other_cannabis_tax"`
	TotalTax          string `json:"total_tax"`
}

Tax represents a CT cannabis monthly tax record

func FetchTax

func FetchTax(appToken string, maxCacheAge time.Duration) ([]Tax, error)

FetchTax fetches all CT cannabis tax data from the CT API

func (Tax) CSVHeaders

func (t Tax) CSVHeaders() string

CSVHeaders returns the CSV headers for the Tax struct

func (Tax) CSVValue

func (t Tax) CSVValue() string

CSVValue returns the CSV value for the Tax struct

type WeeklySales

type WeeklySales struct {
	WeekEnding                   string `json:"unnamed_column"` // ISO 8601 datetime
	AdultUse                     string `json:"adult_use"`
	Medical                      string `json:"medical"`
	Total                        string `json:"total"`
	AdultUseProductsSold         string `json:"adult_use_products_sold"`
	MedicalProductsSold          string `json:"medical_products_sold"`
	TotalProductsSold            string `json:"total_products_sold"`
	AdultUseCannabisAveragePrice string `json:"adult_use_cannabis_average_product_price"`
	MedicalMarijuanaAveragePrice string `json:"medical_marijuana_average_product_price"`
}

WeeklySales represents a CT cannabis weekly retail sales record

func FetchWeeklySales

func FetchWeeklySales(appToken string, maxCacheAge time.Duration) ([]WeeklySales, error)

FetchWeeklySales fetches all CT cannabis weekly sales data from the CT API

func (WeeklySales) CSVHeaders

func (s WeeklySales) CSVHeaders() string

CSVHeaders returns the CSV headers for the WeeklySales struct

func (WeeklySales) CSVValue

func (s WeeklySales) CSVValue() string

CSVValue returns the CSV value for the WeeklySales struct

type Zoning added in v0.2.0

type Zoning struct {
	Town           string `json:"town"`
	State          string `json:"state"`
	Status         string `json:"status"`
	DateAdopted    string `json:"date_adopted"`
	DateEffective  string `json:"date_effective"`
	Notes          string `json:"notes"`
	DateAdopted1   string `json:"date_adopted_1"`
	DateEffective1 string `json:"date_effective_1"`
	Notes1         string `json:"notes_1"`
}

Zoning represents a CT cannabis zoning record for a municipality

func FetchZoning added in v0.2.0

func FetchZoning(appToken string, maxCacheAge time.Duration) ([]Zoning, error)

FetchZoning fetches all CT cannabis zoning data from the CT API

func (Zoning) CSVHeaders added in v0.2.0

func (z Zoning) CSVHeaders() string

CSVHeaders returns the CSV headers for the Zoning struct

func (Zoning) CSVValue added in v0.2.0

func (z Zoning) CSVValue() string

CSVValue returns the CSV value for the Zoning struct

Jump to

Keyboard shortcuts

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