Giter Site home page Giter Site logo

statsandbooze's Introduction

statsAndBooze

The goal of statsAndBooze is to find the optimal date for a happy hour, i.e.Β the closest date when all the participants are available.

Installation

You can install the development version of statsAndBooze from GitHub with:

# install.packages("devtools")
devtools::install_github("Anastasia-psy/statsAndBooze")

Usage and Examples

To load the package:

library(statsAndBooze)

The input must be a list of names with the available dates for each participant and must be transformed from string to data format. Use the function parse_dates() for this task.

In the list, you must specify the dates in YYYY-MM-DD format like in the example below:

dates<- list(
  andrea = "2023-03-29", # exactly with this format
  federico = "2023-03-30" # exactly with this format
)

parse_dates(dates)
#> $andrea
#> [1] "2023-03-29"
#> 
#> $federico
#> [1] "2023-03-30"

You can also specify a time interval when a participant is available. This must be done in the following format: YYYY-MM-DD / YYYY-MM-DD (see example).

dates <- list(
  andrea = c("2023-04-01", "2023-04-03 / 2023-04-05"),
  federico = c("2023-04-02", "2023-04-03"),
  chiara = "2023-04-02 / 2023-04-03"
)

parse_dates(dates)
#> $andrea
#> [1] "2023-04-01" "2023-04-03" "2023-04-04" "2023-04-05"
#> 
#> $federico
#> [1] "2023-04-02" "2023-04-03"
#> 
#> $chiara
#> [1] "2023-04-02" "2023-04-03"

You can also specify the dates using the workdays names in your local language in the abbreviated form. To see the available values for days of week, run the function lubridate::wday(x, label = TRUE).The names of the weekdays refer to the subsequent 7 days with respect to the current day (included) when the function is run. For each person the dates must be specified or in date form or as days of the week, but not in a mixed form. See the following example:

lubridate::wday("2023-04-28", label = TRUE)
#> [1] ven
#> Levels: dom < lun < mar < mer < gio < ven < sab

dates <- list(
  andrea = c("sab", "gio", "dom"),
  federico = c("2023-04-27", "2023-04-30"),
  chiara = "2023-04-28 / 2023-04-30"
)

parse_dates(dates)
#> $andrea
#> [1] "2023-04-29" "2023-04-30" "2023-05-04"
#> 
#> $federico
#> [1] "2023-04-27" "2023-04-30"
#> 
#> $chiara
#> [1] "2023-04-28" "2023-04-29" "2023-04-30"

Finally, to define the date for a happy hour, you need the function decide_happy_hour(), which takes the output of the function parse_dates as input. In case there are several dates when all the participants are available, the function returns the nearest suitable date. See the example below.

dates <- list(
  andrea = c("sab", "gio", "dom"),
  federico = c("2023-04-27", "2023-04-30"),
  chiara = "2023-04-28 / 2023-04-30"
)

parsed_dates <- parse_dates(dates)

decide_happy_hour(parsed_dates)
#> [1] "2023-04-30"

The function returns Date of length 0 if there is no date when all the participants are available.

statsandbooze's People

Contributors

anastasia-psy avatar paolagalfrascoli avatar muhammadharoonshaukat avatar

Stargazers

Andrea Gilardi avatar

Watchers

 avatar

statsandbooze's Issues

Package review

Dear all, I just checked your package and I think that you did a great job, congratulations πŸŽ‰ I think there are just a few minor points that are not correct.

  1. It is not helpful to test a condition like if (x == TRUE) since the object x can immediately be evaluated as TRUE or FALSE without that extra step

if (all(!stringr::str_detect(unlist(x), paste(c("lun", "mar", "mer", "gio", "ven", "sab", "dom"),collapse = '|')) == TRUE)) {

  1. Looking at the README, the documentation, and the R code, it looks like you decided that the weekdays must be coded using the local language. This is fine but, unfortunately, you also need to properly adjust the lubridate::wday function to accommodate your decision, otherwise the following example fails:
remotes::install_github("Anastasia-psy/statsAndBooze", quiet = TRUE)
library(statsAndBooze)
dates <- list(a = "dom")
parse_dates(dates)
#> $a
#> Date of length 0

# since
lubridate::wday("2023-05-07", label = TRUE)
#> [1] Sun
#> Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat

Created on 2023-05-05 with reprex v2.0.2

In particular, you need to set lubridate::wday(next_week, label = TRUE, locale = "italian") instead of the following piece of code:

weekday = lubridate::wday(next_week, label = TRUE))

  1. The documentation is fine but you forgot to add extra tests regarding the new functionalities.

I will send you a short report about the remaining part of the exam in a few minutes.

Andrea

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.