---
title: "warabandi"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{warabandi}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

# Warabandi or Roster of Turn
**Introduction:**
This function will generate roster for a week (168 hrs. or 24X7). Flow time
of a watercourse to an individual farmer calculate based on their holding area
(bigga or hectares), This flow time roster generated by this function known as
"warabandi" in canal irrigated agricultural areas (Punjab, Rajasthan, Haryana
and Some areas of Pakistan)

# Load Package

```{r setup}
library(warabandi)
```
## data structure of input data
```{r}
head(warabandi_data)

```

#Calulation of roster 
Here we are not writing output to reduce vignettes and space
```{r}
output<-warabandi(file = warabandi_data, output = FALSE, nof = "my_file.csv")
```

#Lets take a look at output 
Output generated by package is a list of different objects.
1. Flow time per unit area in minutes
2. Rakva or total area under command subject to be irrigated
3. Bharai or fillig time; as a compensation 
4. Jharai or empty time
5. Weekdays or total duration has to be divided
6. Final table calculated by warabandi saved as a output file to the working 
   directory
```{r}
output[1:5]
Report_Table<-data.frame(output[6])
head(Report_Table)
```

# Report generation of warabandi
 Generation of the report in printable format which can be supplied or distribut-
 ed among all the farmers. This step is highle depend on the external packages 
 (knitr, flextable). Code chunk provide below is a sample which can be modified 
 as per user need like header and fotters.
 Lets read output file generated by warabandi package
```{r}
data2<-Report_Table
```

# Lets make table

```{r}
flextable::flextable(head(data2))
```

# Lets generate report for individual farmer

```{r}
data3 <- data.frame(head(data2))
invisible(by(data3, seq_len(nrow((data3))), function(row) {
  chak<-"Chak-38 R.B" 
distributries<- "R.B II"
dateOI<-date()
dateOd<-"Date of distribution __/__/____"
note1<-"Note: All schedules issued before this, are cancelled"
Year_o_Valid<-"Year: April 2019 to 2025"
Issue<-"Issue Serial No:________/___"
Jal_upbhokta<-"Jal Upbhokta Sangam:"
d5 <-flextable::fit_to_width(flextable::flextable(row), max_width = 7,
                             inc=1L, max_iter = 20)
d5 <- flextable::add_header_lines(d5, c(paste(Year_o_Valid,"\t","\t", chak), paste(Jal_upbhokta,
                                                                                   distributries, "\t","\t", Issue, "\t","\t","\t","\t",  dateOI)))
d5 <-flextable::add_footer_lines(d5, 
                                 c(paste(dateOd, "\t", "\t", note1), 
                                   paste("President", "\n", "\n", "\n", 
                                         Jal_upbhokta, distributries)))
 #flextable::flextable_to_rmd(d5)

 }))
```

# Lets take a look at report for individual farmer

![](TableIndividual.png)

# Contact us
That's all! 
Thanks for being here.
Let me know if you heve any doubt about this package or issue
Harvinder Singh
Department of pharmacology
PGIMER, Chandigarh (160012)
harvindermaan4@gmail.com
ORCID https://orcid.org/0000-0002-6349-3143
