-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hkts #3
base: master
Are you sure you want to change the base?
Add hkts #3
Changes from all commits
2decae5
8375696
01c1dbe
866bbc4
400089e
3ae5850
8c234a1
24ad063
66f511e
e258075
b87f60c
eead56c
63a15b9
27686ca
4221fbf
39dd332
ec3cb09
ae0784f
fbdfd6e
1ba31fe
8408ef6
cce900d
4dde8e1
d47f9cc
2823ad4
de55d10
671dbae
56da5c0
b6d9b0b
b900f7a
5836d31
073a506
82cdc36
5a41a96
45ec47c
44eb4c9
b15e3b9
0c47c13
6e013e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
|
||
- name: Login to DockerHub | ||
run: docker login -u '${{secrets.DOCKER_HUB_USER}}' -p '${{secrets.DOCKER_HUB_PASSWORD}}' | ||
|
||
- name: Build docker image | ||
run: sbt docker:publish |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set execute permissions on script | ||
run: chmod +x ./integrationTest.sh | ||
- name: Run integration test | ||
env: | ||
MAPBOX_API_TOKEN: ${{ secrets.MAPBOX_API_TOKEN }} | ||
run: ./integrationTest.sh "$MAPBOX_API_TOKEN" | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Formatting | ||
run: sbt scalafmtSbtCheck scalafmtCheck test:scalafmtCheck |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ build/ | |
.idea | ||
.bsp | ||
|
||
outputDir | ||
|
||
logs/ | ||
|
||
# metals lsp files | ||
.bloop | ||
.metals | ||
metals.sbt |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,47 +8,61 @@ Create an image of a map with given point coordinates. | |
You need to have [SBT](https://www.scala-sbt.org/download.html) installed on your machine to run this project. | ||
|
||
## Installation | ||
|
||
To install GeoJson Formatter, follow these steps: | ||
|
||
Windows/Mac/Linux: | ||
|
||
```bash | ||
$ git clone https://github.com/arnasbr/geopoint-visualizer.git | ||
$ cd geopoint-visualizer | ||
``` | ||
|
||
## Api Token | ||
|
||
Create an account in https://account.mapbox.com/ | ||
|
||
Use your `Default public token` (or create a new one) | ||
|
||
## Usage | ||
Start sbt, pass in input. `run plot --help` for help | ||
|
||
``` | ||
Usage: geopoint-visualizer plot [--swap] [--download] [--browser] [--img_size <integer>] [--input <string>] | ||
Usage: geopoint-visualizer plot --token <string> [--swap] [--future] [--img_size <integer>] [--input <string>] | ||
|
||
Plots given points on a map | ||
|
||
Options and flags: | ||
--help | ||
Display this help text. | ||
--token <string> | ||
Mapbox api token | ||
--swap | ||
Flag to indicate if latitude and longitude should be swapped (default - false) | ||
--download | ||
Flag to indicate if image should be downloaded to outputDir | ||
--browser | ||
Flag to indicate if image should be opened in browser | ||
Flag to indicate if latitude and longitude should be swapped | ||
--future | ||
Flag to indicate if app should be run using Futures instead of IO (cats effect) | ||
--img_size <integer> | ||
Image size 1-1280 (default - 1000) | ||
--input <string> | ||
Input file path (default - inputDir/input.json) | ||
``` | ||
|
||
If neither --download nor --browser flags are chosen, by default only --download will happen | ||
#### Examples | ||
```bash | ||
$ sbt "run plot --token <your_api_token> --swap --img_size 1000 --input inputDir/input.json" | ||
|
||
#### Example | ||
$ sbt "run plot --token <your_api_token> --swap --future" //use default image size and input file and use Future | ||
``` | ||
|
||
#### Running with Docker | ||
```bash | ||
$ sbt | ||
sbt: geopoint-visualizer> run plot --swap --download --browser --img_size 1000 --input "inputDir/input.json" | ||
$ docker run\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you must mention all optional flags and default values |
||
--user $(id -u):$(id -g) \ | ||
-v ./inputDir:/app/inputDir \ | ||
-v ./outputDir:/app/outputDir \ | ||
-it arnasbr/geopoint-visualizer:latest \ | ||
plot \ | ||
--token <your_api_token> \ | ||
--swap | ||
``` | ||
|
||
When using a different input file than the default inputDir/input.json, don't forget to change the -v volume and use the --input tag. | ||
|
||
## Result | ||
|
||
![image](https://github.com/arnasbr/geopoint-visualizer/assets/140691866/dd311615-b5e2-4135-b26b-3f69e4e73a20) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# Check if any arguments are passed | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: ./integrationTest.sh <MAPBOX_API_TOKEN>" | ||
echo "You must provide the Mapbox API token as an argument." | ||
exit 1 | ||
fi | ||
|
||
# Check if outputDir/output.png exists and delete it | ||
if test -f "outputDir/output.png"; then | ||
echo "Deleting existing outputDir/output.png." | ||
rm -f "outputDir/output.png" | ||
fi | ||
|
||
token=$1 | ||
|
||
# Run the Scala app with sbt | ||
sbt "run plot --token $token --swap --input integrationTestData/integrationTestInput.json" | ||
|
||
# Check if the output.png file exists | ||
if test -f "outputDir/output.png"; then | ||
echo "outputDir/output.png exists." | ||
exit 0 | ||
else | ||
echo "outputDir/output.png does not exist." | ||
exit 1 | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
[ | ||
[ | ||
51.499619505045594, | ||
-0.12919985466434053 | ||
] | ||
] | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.0") | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.8.1") | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0") |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
import Models.CliArgs | ||
import Models.{CliArgs, FilePath} | ||
import cats.implicits.catsSyntaxTuple5Semigroupal | ||
import com.monovore.decline._ | ||
|
||
object Cli { | ||
private val apiToken: Opts[String] = | ||
Opts | ||
.option[String]( | ||
"token", | ||
help = "Mapbox api token" | ||
) | ||
|
||
private val swapFlag: Opts[Boolean] = Opts | ||
.flag( | ||
"swap", | ||
help = | ||
"Flag to indicate if latitude and longitude should be swapped (default - false)" | ||
help = "Flag to indicate if latitude and longitude should be swapped" | ||
) | ||
.orFalse | ||
|
||
private val downloadFlag: Opts[Boolean] = Opts | ||
private val futureFlag: Opts[Boolean] = Opts | ||
.flag( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's do with zio too. Instead of future flag use enum |
||
"download", | ||
help = "Flag to indicate if image should be downloaded to outputDir" | ||
) | ||
.orFalse | ||
|
||
private val browserFlag: Opts[Boolean] = Opts | ||
.flag( | ||
"browser", | ||
help = "Flag to indicate if image should be opened in browser" | ||
"future", | ||
help = | ||
"Flag to indicate if app should be run using Futures instead of IO (cats effect)" | ||
) | ||
.orFalse | ||
|
||
|
@@ -30,20 +30,21 @@ object Cli { | |
.option[Int]("img_size", help = "Image size 1-1280 (default - 1000)") | ||
.withDefault(1000) | ||
|
||
private val inputFile: Opts[String] = | ||
private val inputFile: Opts[FilePath] = | ||
Opts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. support multiple input files. So you can pass a dir instead and then create image per file |
||
.option[String]( | ||
"input", | ||
help = "Input file path (default - inputDir/input.json)" | ||
) | ||
.withDefault("inputDir/input.json") | ||
.map(FilePath) | ||
.withDefault(FilePath("inputDir/input.json")) | ||
|
||
val command: Opts[CliArgs] = Opts.subcommand( | ||
Command(name = "plot", header = "Plots given points on a map")( | ||
( | ||
apiToken, | ||
swapFlag, | ||
downloadFlag, | ||
browserFlag, | ||
futureFlag, | ||
imageSize, | ||
inputFile | ||
).mapN(CliArgs) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import FeatureCreation.createFeatureCollection | ||
import Parsing.parseInputCoordinates | ||
import sttp.client3.UriContext | ||
import scala.io.BufferedSource | ||
import sttp.model.Uri | ||
|
||
object HelperUtils { | ||
def generateStaticImageUri( | ||
fileSource: BufferedSource, | ||
swapFlag: Boolean, | ||
colors: LazyList[Color], | ||
imageSize: Int, | ||
apiToken: String | ||
): Uri = { | ||
val inputCoordinates = parseInputCoordinates(fileSource, swapFlag) | ||
val featureCollection = createFeatureCollection(inputCoordinates, colors) | ||
|
||
uri"https://api.mapbox.com/styles/v1/mapbox/dark-v11/static/geojson($featureCollection)/auto/${imageSize}x$imageSize?access_token=$apiToken" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make readme a little bit more readable