forked from cloudsftp/Sunangel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
2,648 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Build Develop | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
build: | ||
name: Build Application | ||
strategy: | ||
matrix: | ||
platform: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-build- | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18 | ||
- run: bash build.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: CLI Tests Develop | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
cli_unit_tests: | ||
strategy: | ||
matrix: | ||
platform: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
~/.sunangel/geoelevations | ||
key: ${{ runner.os }}-cli-tests-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-cli-tests- | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18 | ||
- run: bash run_cli_tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Core Tests Develop | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
unit_tests: | ||
strategy: | ||
matrix: | ||
platform: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
~/.sunangel/geoelevations | ||
key: ${{ runner.os }}-core-tests-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-core-tests- | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18 | ||
- run: bash run_core_tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
jobs: | ||
build: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: ${{ runner.os }}-release-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-release | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.18 | ||
- run: bash build_release.sh | ||
- uses: softprops/action-gh-release@v1 | ||
if: startsWith(github.ref, 'refs/tags/') | ||
with: | ||
files: SunangelBinaries* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
go.sum | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
Img | ||
Build | ||
SunangelBinaries* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Launch Package", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "cmd" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Sunangel ![version](https://img.shields.io/badge/v0.1.0-blue.svg) | ||
|
||
[![unit test status](https://github.com/cloudsftp/Sunangel/actions/workflows/core_unit_tests.yaml/badge.svg?branch=develop)](https://github.com/cloudsftp/Sunangel/actions/workflows/core_unit_tests.yaml) | ||
[![unit test status](https://github.com/cloudsftp/Sunangel/actions/workflows/cli_unit_tests.yaml/badge.svg?branch=develop)](https://github.com/cloudsftp/Sunangel/actions/workflows/cli_unit_tests.yaml) | ||
[![build status](https://github.com/cloudsftp/Sunangel/actions/workflows/build.yaml/badge.svg?branch=develop)](https://github.com/cloudsftp/Sunangel/actions/workflows/build.yaml) | ||
[![release status](https://github.com/cloudsftp/Sunangel/actions/workflows/release.yaml/badge.svg)](https://github.com/cloudsftp/Sunangel/actions/workflows/release.yaml) | ||
|
||
## Motivation | ||
|
||
Weather Apps and other Sources of information give bad results for the time of sunset. | ||
Especially in locations with many hills. | ||
|
||
This project aims to provide a better prediction of the time, the sun actually crosses the horizon. | ||
In order to do so, we use elevation data to compute the horizon profile for a given location. | ||
Then we search for the time, the altitude of the sun is right at the horizon. | ||
|
||
## Installation | ||
|
||
### From source | ||
|
||
``` | ||
git clone https://github.com/cloudsftp/Sunangel.git | ||
cd Sunangel | ||
git checkout master # make sure you are at the latest release, not on develop | ||
./install.sh | ||
``` | ||
|
||
### Binary | ||
|
||
Download binaries from the [releases](https://github.com/cloudsftp/Sunangel/releases). | ||
|
||
## Usage | ||
|
||
### Use `location` to manage stored locations | ||
|
||
``` | ||
Usage: location COMMAND [OPTIONS] | ||
COMMAND OPTIONS | ||
help Prints this information | ||
list Lists all stored locations | ||
add NAME LAT LONG Adds a location | ||
delete NAME Deletes a location | ||
``` | ||
|
||
### Use `sunset` to calculate the sunset for a given location | ||
|
||
``` | ||
Usage: sunset (help | NAME | LAT LONG) [d=DAYOFFSET] [r=STARTRADIUS] | ||
Either NAME or LAT LONG is required as the first set of arguments | ||
If a NAME is entered, the program checks the database for stored locations | ||
If LAT and LONG are entered, the program uses these coordinates | ||
DAYOFFSET: Integer offset of the day relativeto today (tomorrow is d=1) | ||
STARTRADIUS: Integer radius to ignore when computing the horizon (one kilometer is r=1000) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package angle | ||
|
||
import "math" | ||
|
||
const ( | ||
degreesPerRadian float64 = 180 / math.Pi | ||
degreesPerRotation float64 = 360 | ||
) | ||
|
||
// DegreesFromRadians returns the angle in degrees which is given in radians. | ||
// It will be in the range [0, 360) | ||
func DegreesFromRadians(radians float64) float64 { | ||
degrees := radians * degreesPerRadian | ||
return NormalizeDegrees(degrees) | ||
} | ||
|
||
// NormalizeDegrees resturns the normalized angle in degrees. | ||
// It will be in the range [0, 360) | ||
func NormalizeDegrees(degrees float64) float64 { | ||
degrees = math.Mod(degrees, degreesPerRotation) | ||
if degrees < 0 { | ||
degrees += degreesPerRotation | ||
} | ||
return degrees | ||
} | ||
|
||
// NormalizeDegrees resturns the normalized angle in degrees. | ||
// It will be in the range [-180, 180) | ||
func NormalizeDegreesLatitude(degrees float64) float64 { | ||
degrees = NormalizeDegrees(degrees) | ||
if degrees >= degreesPerRotation/2 { | ||
degrees -= degreesPerRotation | ||
} | ||
return degrees | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package angle | ||
|
||
import "math" | ||
|
||
const ( | ||
radiansPerDegree float64 = math.Pi / 180 | ||
radiansPerRotation float64 = 2 * math.Pi | ||
) | ||
|
||
// RadiansFromDegrees returns the angle in radians which is given in degrees. | ||
// It will be in the range [0, 2π) | ||
func RadiansFromDegrees(degrees float64) float64 { | ||
radians := degrees * radiansPerDegree | ||
return NormalizeRadians(radians) | ||
} | ||
|
||
// NormalizeRadians returns the normalized angle in radians. | ||
// It will be in the range [0, 2π) | ||
func NormalizeRadians(radians float64) float64 { | ||
radians = math.Mod(radians, radiansPerRotation) | ||
if radians < 0 { | ||
radians += radiansPerRotation | ||
} | ||
return radians | ||
} | ||
|
||
// NormalizeRadiansLatitude returns the normalized angle in radians. | ||
// It will be in the range [-π, π) | ||
func NormalizeRadiansLatitude(radians float64) float64 { | ||
radians = NormalizeRadians(radians) | ||
if radians >= radiansPerRotation/2 { | ||
radians -= radiansPerRotation | ||
} | ||
return radians | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package args | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
type LocationMode int | ||
|
||
const ( | ||
List LocationMode = iota | ||
Add | ||
Delete | ||
) | ||
|
||
type LocationArguments struct { | ||
Mode LocationMode | ||
Name string | ||
Latitude float64 | ||
Longitude float64 | ||
} | ||
|
||
func ParseLocationArguments(args []string) (*LocationArguments, error) { | ||
arguments := &LocationArguments{} | ||
if len(args) < 2 { | ||
return nil, fmt.Errorf("too few argumeents") | ||
} | ||
|
||
switch args[1] { | ||
case "list": | ||
arguments.Mode = List | ||
|
||
if len(args) > 2 { | ||
return nil, fmt.Errorf("too many arguments for command list") | ||
} | ||
case "add": | ||
arguments.Mode = Add | ||
if len(args) != 5 { | ||
return nil, fmt.Errorf("wrong number of arguments for command add") | ||
} | ||
|
||
arguments.Name = args[2] | ||
|
||
var err error | ||
arguments.Latitude, err = strconv.ParseFloat(args[3], 64) | ||
if err != nil { | ||
return nil, fmt.Errorf("third argument is NaN") | ||
} | ||
|
||
arguments.Longitude, err = strconv.ParseFloat(args[4], 64) | ||
if err != nil { | ||
return nil, fmt.Errorf("fourth argument is NaN") | ||
} | ||
case "delete": | ||
arguments.Mode = Delete | ||
if len(args) != 3 { | ||
return nil, fmt.Errorf("wrong number of arsuments for command delete") | ||
} | ||
|
||
arguments.Name = args[2] | ||
case "help": | ||
return nil, fmt.Errorf("help requested") | ||
default: | ||
return nil, fmt.Errorf("%s is not recognized as command", args[1]) | ||
} | ||
|
||
return arguments, nil | ||
} | ||
|
||
func PrintLocationUsage(cmd string, err error) { | ||
fmt.Printf("%v\n\n", err) | ||
fmt.Printf("Usage: %s COMMAND [OPTIONS]\n\n", cmd) | ||
fmt.Println(" COMMAND OPTIONS") | ||
fmt.Println(" help Prints this information") | ||
fmt.Println(" list Lists all stored locations") | ||
fmt.Println(" add NAME LAT LONG Adds a location") | ||
fmt.Println(" delete NAME Deletes a location") | ||
fmt.Println() | ||
|
||
os.Exit(2) | ||
} |
Oops, something went wrong.