-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUNICEF LCRP-2017-R Health-UNICEF Extraction Script.R
executable file
·95 lines (80 loc) · 4.69 KB
/
UNICEF LCRP-2017-R Health-UNICEF Extraction Script.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
################################################################################
# Organization : UNICEF
# Author : Raed Abdel Sater
# Title : Information management officer
# Copyright (c) 2017 UNICEF
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
################################################################################
opt <- options(warn = -1)
rm(list = ls())
library("activityinfo")
#library("xlsx")
#library("XLConnect")
# Replace 'NA' with the numeric identifier of your database (e.g. 1234):
database.id <- 6443
# Uncomment the following command if you want to log in manually, leave commented
# out if you have stored your login credentials on your local machine.
if (is.na(database.id)) {
stop("you forgot to set the database identifier at the top of this script!")
}
values <- getDatabaseValueTable(database.id,
col.names = c(database.id = "databaseId",
indicator.id = "indicatorId",
indicator.name = "indicatorName",
indicator.value = "value",
location.adminlevel.cadastral_area = "cadastral.area",
location.adminlevel.governorate = "governorate",
location.adminlevel.caza = "caza",
location.adminlevel.cadastral_area.code = "cadCod",
partner.label = "partnerName",
partner.description = "partnerFullName",
location.name = "locationName",
location.code = "locationCode",
start_date = "month",
"Funded by" = "Funded.by"))
# Generating values dataframe
cat("Done. The results are in a data frame called 'values'.\n")
# Subsetting Values to UNICEF interventions dataset only
values$month <-strftime(values$month,"%Y-%m")
UNICEF <- values
# Creating a folder and export the extraction as a csv file to "UNICEF" folder after creating the folder in case it doesn't exist
db.6443hn.lcrp <- values
#mainDir <-"C:\\Work/Information Management/AI Extractions/"
#subDir <- "Sector"
#ifelse(!dir.exists(file.path(mainDir, subDir)), dir.create(file.path(mainDir, subDir)), FALSE)
#setwd(file.path(mainDir, subDir))
outfilname<- paste(Sys.Date(), "_HN.csv", sep="")
write.csv(db.6443hn.lcrp,outfilname)
cat("Done. The results of UNICEF interventions are in a data frame called 'UNICEF'.\n")
# Creating a folder and export the extraction as a csv file to "UNICEF" folder after creating the folder in case it doesn't exist
db.6443unihn.lcrp <- UNICEF
#mainDir <-"C:\\Work/Information Management/AI Extractions/"
#subDir <- "UNICEF"
#ifelse(!dir.exists(file.path(mainDir, subDir)), dir.create(file.path(mainDir, subDir)), FALSE)
#setwd(file.path(mainDir, subDir))
outfilname<- paste(Sys.Date(), "_UNICEF_HN.csv", sep="")
write.csv(db.6443unihn.lcrp,outfilname)
cat("Done. The results of UNICEF interventions are in a data frame called 'UNICEF'.\n")
# #Writing UNICEF extraction to the Dashboard
# XLConnect::writeWorksheetToFile("s://2- Programmes/SPPME/7.PME/21-DASHBOARDS_2017/DASHBOARD_2017- HN.xlsx",db.6443unihn.lcrp, "HNDB",clearSheets = TRUE,styleAction = XLC$STYLE_ACTION.NONE)
# cat("UNICEF results are available on the Dashboard'.\n")
#
# # Workbook <- loadWorkbook("s://2- Programmes/SPPME/7.PME/21-DASHBOARDS_2017/ADHOC_EXTRACTIONS/TEST/TEST.xlsx")
# # writeData(Workbook,sheet = "MasterList",db.6500uniba.lcrp)