Skip to content

Commit

Permalink
Merge pull request #55 from IDEMSInternational/main
Browse files Browse the repository at this point in the history
Update from MC
  • Loading branch information
lilyclements authored Jan 16, 2024
2 parents 8e6cf9d + 94b80b6 commit 7d85ce6
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 120 deletions.
7 changes: 5 additions & 2 deletions R/total_temperature_summaries.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ total_temperature_summaries <- function(country,
}
}
}
if (length(summary_data) == 2) summary_data <- dplyr::full_join(summary_data[[1]], summary_data[[2]])
if (length(summary_data) == 2){
summary_data <- dplyr::full_join(summary_data[[1]], summary_data[[2]])
} else {
summary_data <- summary_data[[1]]
}
summary_data$year <- as.integer(summary_data$year)
if ("month" %in% names(summary_data)){
summary_data$month <- as.integer(forcats::as_factor(summary_data$month))
}

list_return <- list(definitions, summary_data)
return(list_return) # return a list with the metadata and the data itself
}
42 changes: 37 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,51 @@ knitr::opts_chunk$set(
)
```

# epicsawrap
# epicsawrap: R Package for Integrating rpicsa and epicsadata Functions for API Apps

<!-- badges: start -->
[![R-CMD-check](https://github.com/IDEMSInternational/epicsawrap/workflows/R-CMD-check/badge.svg)](https://github.com/IDEMSInternational/epicsawrap/actions)
[![Codecov test
coverage](https://codecov.io/gh/IDEMSInternational/epicsawrap/branch/main/graph/badge.svg)](https://app.codecov.io/gh/IDEMSInternational/epicsawrap?branch=main)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->

The goal of epicsawrap is to ...
## Overview

**epicsawrap** is an R package that brings together the functionality of **rpicsa** and **epicsadata** packages to be used in creating API applications for crop and climate analysis. It provides a convenient interface for accessing and utilizing the functions from both packages, enabling the development of web-based tools and services for agricultural decision support.

The package combines the capabilities of **rpicsa** for PICSA and climatic analysis for crops with **epicsadata** for retrieving climate and weather data, creating a powerful tool for addressing the needs of farmers, agronomists, and researchers.

## Installation

You can install the development version of epicsawrap from [GitHub](https://github.com/) with:
You can install **epicsawrap** from CRAN using the following command:

``` r
# install.packages("devtools")
# Install the 'devtools' package if you haven't already
if (!require(devtools)) {
install.packages("devtools")
}

# Install 'epicsawrap' from GitHub
devtools::install_github("IDEMSInternational/epicsawrap")
```
```


## Documentation
For detailed information on each function, including arguments, usage, and examples, please refer to the package documentation. You can access it using the following command:

```{r, message = FALSE, warning = FALSE, eval=FALSE, include=TRUE}
?epicsawrap
```

The GitHub page for the `rpicsa` package can be found [here](https://github.com/IDEMSInternational/rpicsa).
The GitHub page for the `epicsadata` package can be found [here](https://github.com/IDEMSInternational/epicsadata).

## Contributing
We welcome contributions from the community. If you have any bug reports, feature requests, or would like to contribute code to rpicsa, please visit our GitHub repository.

## License
This package is open-source and distributed under the GNU Lesser General Public License v3.0 License. Feel free to use, modify, and distribute it as needed.

## Contact
If you have any questions, suggestions, or feedback, please feel free to reach out to us.
61 changes: 56 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,73 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# epicsawrap
# epicsawrap: R Package for Integrating rpicsa and epicsadata Functions for API Apps

<!-- badges: start -->

[![R-CMD-check](https://github.com/IDEMSInternational/epicsawrap/workflows/R-CMD-check/badge.svg)](https://github.com/IDEMSInternational/epicsawrap/actions)
[![Codecov test
coverage](https://codecov.io/gh/IDEMSInternational/epicsawrap/branch/main/graph/badge.svg)](https://app.codecov.io/gh/IDEMSInternational/epicsawrap?branch=main)
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->

The goal of epicsawrap is to …
## Overview

**epicsawrap** is an R package that brings together the functionality of
**rpicsa** and **epicsadata** packages to be used in creating API
applications for crop and climate analysis. It provides a convenient
interface for accessing and utilizing the functions from both packages,
enabling the development of web-based tools and services for
agricultural decision support.

The package combines the capabilities of **rpicsa** for PICSA and
climatic analysis for crops with **epicsadata** for retrieving climate
and weather data, creating a powerful tool for addressing the needs of
farmers, agronomists, and researchers.

## Installation

You can install the development version of epicsawrap from
[GitHub](https://github.com/) with:
You can install **epicsawrap** from CRAN using the following command:

``` r
# install.packages("devtools")
# Install the 'devtools' package if you haven't already
if (!require(devtools)) {
install.packages("devtools")
}

# Install 'epicsawrap' from GitHub
devtools::install_github("IDEMSInternational/epicsawrap")
```

## Documentation

For detailed information on each function, including arguments, usage,
and examples, please refer to the package documentation. You can access
it using the following command:

``` r
?epicsawrap
```

The GitHub page for the `rpicsa` package can be found
[here](https://github.com/IDEMSInternational/rpicsa). The GitHub page
for the `epicsadata` package can be found
[here](https://github.com/IDEMSInternational/epicsadata).

## Contributing

We welcome contributions from the community. If you have any bug
reports, feature requests, or would like to contribute code to rpicsa,
please visit our GitHub repository.

## License

This package is open-source and distributed under the GNU Lesser General
Public License v3.0 License. Feel free to use, modify, and distribute it
as needed.

## Contact

If you have any questions, suggestions, or feedback, please feel free to
reach out to us.
1 change: 0 additions & 1 deletion tests/test.R

This file was deleted.

4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(epicsawrap)

test_check("epicsawrap")
34 changes: 15 additions & 19 deletions tests/testthat/test-annual_rainfall_summaries.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# library(testthat)
# library(rpicsa)
#
# # Test case 1
# country <- "zm"
# station_id <- "01122"
# summaries <- c("annual_rain")
# result <- epicsawrap::annual_rainfall_summaries(country, station_id, summaries)
#
# definitions <- definitions(country = "zm", station_id = "16",
# summaries = summaries)
# epicsadata::get_daily_data(country = country, station_id = station_id)
#
# country <- "zm"
# station_id_2 <- "16"
# summaries_2 <- c("start_rains", "end_rains", "annual_rain", "seasonal_rain")
# result_2 <- epicsawrap::annual_rainfall_summaries(country, station_id_2, summaries_2)
#
library(testthat)
library(epicsawrap)

# Test case 1
epicsadata::gcs_auth_file(file = "testdata/e-picsa-e630400792e7.json")
test_1_results <- readRDS("testdata/test_1_annual_summaries.rds")
country <- "zm"
station_id <- "test_1"

test_that("Correct summaries are calculated", {
result <- annual_rainfall_summaries(country, station_id)
expect_true(identical(result[[2]], test_1_results))
})

# test_that("Correct summaries are calculated", {
# # Test case 2
# expect_no_error(result)
Expand All @@ -28,7 +24,7 @@
# expect_error(epicsawrap::annual_rainfall_summaries(country, station_id, "end_season"))
#
# # Test case 2: Error is thrown if start_ is not calculated but needed
# expect_error(epicsawrap::annual_rainfall_summaries(country, station_id_2, c("end_rains", "seasonal_rain")))
# expect_error(epicsawrap::annual_rainfall_summaries(country, station_id, c("seasonal_rain")))
#
# # Test case 3: Warning if both end are given and seasonal wanted
# expect_warning(epicsawrap::annual_rainfall_summaries(country, station_id_2, c("start_rains", "end_rains", "end_season", "seasonal_rain")))
Expand Down
58 changes: 18 additions & 40 deletions tests/testthat/test-crop_success_probabilities.R
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
# library(testthat)
#
# # External functions call
# # Test case 1: Test with all parameter
# result <- epicsawrap::crop_success_probabilities(
# country = "zm",
# station_id = "16",
# planting_dates = c(92, 122, 153),
# water_requirements = c(300, 500, 700),
# planting_length = c(120, 180),
# start_before_season = TRUE
# )
#
# # Test case 2: Test with missing planting_length parameter
# result_2 <- epicsawrap::crop_success_probabilities(
# country = "zm",
# station_id = "16",
# planting_dates = c(1, 2, 3),
# water_requirements = c(100, 200, 300),
# start_before_season = TRUE
# )
#
# # Test case 2: Test with all missing parameters
# result_3 <- epicsawrap::crop_success_probabilities(
# country = "zm",
# station_id = "16"
# )
#
# # Define test cases
# test_that("crop_success_probabilities returns correct results", {
# expect_no_error(result)
# expect_no_error(result_2)
# expect_no_error(result_3)
# })
#
# # Define test cases
# test_that("crop_success_probabilities returns same results whether parameters are defined or not", {
# expect_identical(result[[2]], result_3[[2]])
# })
#
library(testthat)
library(epicsawrap)

# Test case 1
epicsadata::gcs_auth_file(file = "testdata/e-picsa-e630400792e7.json")
test_1_results <- readRDS("testdata/test_1_crop_success_probabilities.rds")
country <- "zm"
station_id <- "test_1"
test_that("Correct summaries are calculated", {
result <- crop_success_probabilities(country, station_id, water_requirements = c(0, 100, 300))
expect_true(identical(result[[2]], test_1_results))
})


crop_success_probabilities(country, "01122", water_requirements = c(0, 100, 300))


daily <- epicsadata::get_daily_data(country = country, station_id = station_id)
35 changes: 15 additions & 20 deletions tests/testthat/test-season_start_probabilities.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
# library(testthat)
#
# # External functions call
# # Test case 1: Test with all parameters
# result <-
# season_start_probabilities(
# country = "zm",
# station_id = "16",
# start_dates = c(10, 20, 100)
# )
#
# # Test case 2: Test with missing parameters
# result_2 <-
# season_start_probabilities(country = "zm", station_id = "16")
#
# # Define test cases
# test_that("season_start_probabilities returns correct results", {
# expect_no_error(result)
# expect_no_error(result_2)
# })
library(testthat)
library(epicsawrap)

# Test case 1
epicsadata::gcs_auth_file(file = "testdata/e-picsa-e630400792e7.json")
test_1_results <- readRDS("testdata/test_1_season_start_probabilities.rds")
country <- "zm"
station_id <- "test_1"
test_that("Correct summaries are calculated", {
result <- season_start_probabilities(country, station_id, c(0, 150, 300))
expect_true(identical(result[[2]], test_1_results))
})



44 changes: 17 additions & 27 deletions tests/testthat/test-total_temperature_summaries.R
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
# library(testthat)
#
# # Test case 1: Test with to = "annual"
# result <- epicsawrap:::total_temperature_summaries(
# country = "zm",
# station_id = "23",
# summaries = c("mean_tmin", "mean_tmax"),
# to = "annual"
# )
#
# # Test case 2: Test with to = "monthly"
# result_2 <- epicsawrap:::total_temperature_summaries(
# country = "zm",
# station_id = "1",
# summaries = c("mean_tmin", "mean_tmax"),
# to = "monthly"
# )
#
# # Define test cases
# test_that("total_temperature_summaries returns correct results", {
# # Mock the necessary external functions or datasets if needed
# expect_length(result, 2)
# expect_length(result_2, 2)
#
# expect_no_error(result)
# expect_no_error(result_2)
# })
library(testthat)
library(epicsawrap)

# Test case 1
epicsadata::gcs_auth_file(file = "testdata/e-picsa-e630400792e7.json")
test_1_annual <- readRDS("testdata/test_1_annual.rds")
test_1_monthly <- readRDS("testdata/test_1_monthly.rds")
country <- "zm"
station_id <- "test_1"

test_that("Correct summaries are calculated", {
result_annual <- annual_temperature_summaries(country, station_id)
result_monthly <- monthly_temperature_summaries(country, station_id)

expect_true(identical(result_annual[[2]], test_1_annual))
expect_true(identical(result_monthly[[2]], test_1_monthly))
})
2 changes: 1 addition & 1 deletion tests/.gitignore → tests/testthat/testdata/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
e-picsa-e630400792e7.json
test.R
epicsae630400792e7.json
Loading

0 comments on commit 7d85ce6

Please sign in to comment.