1
- # Creates Flattr summary from "Monthly Revenue" reports
2
- # Started by Katrin from the KonScience Podcast in Sept. 2014
3
-
4
- # IMPORTANT: Adjust folder path that contains all the downloaded .csv files here
5
- # Windows: Please use double backslashes like C:\\User\\YOU...
6
- # Linux & Mac: /Users/YOU/ can be abbreviated as '~/...'
7
- path_to_flattr_reports <- " /Users/YOU/Flattr/"
8
-
1
+ # READ ME: https://github.com/KonScience/Summarize-Flattr-Reports#summarize-flattr-reports
9
2
3
+ # assumes all .csv files were downloaded into same folder
4
+ first_flattr_file <- file.choose()
5
+ flattr_dir <- dirname(first_flattr_file ) # learned from http://stackoverflow.com/a/18003224
10
6
11
7
# saves original working directory and sets new one as provided above
12
8
original_wd <- getwd()
13
- setwd(path_to_flattr_reports )
9
+ setwd(flattr_dir )
14
10
15
11
# get filenames of Flattr Monthly Revenue CSVs
16
- Flattr_filenames <- list.files(path_to_flattr_reports ,
12
+ Flattr_filenames <- list.files(flattr_dir ,
17
13
pattern = " flattr-revenue-[0-9]*.csv"
18
14
)
19
15
20
- # // TODO find easier way to select path, e.g.
21
- # - auto-use folder where script runs from // TODO adjust ReadMe.md
22
- # - prompt user for path, all files (file.choose selects only one) or 1st file and find others in same folder // TODO remove original_wd code
23
-
24
16
# read data from CSVs into data frame
25
17
raw <- do.call(" rbind" ,
26
- lapply(Flattr_filenames ,
27
- read.csv ,
28
- sep = " ;" ,
29
- dec = " ," , # convert decimal separator from , to . for following calculations
30
- stringsAsFactors = FALSE #
31
- )
32
- ) # Function structure learned from https://stat.ethz.ch/pipermail/r-help/2010-October/255593.html
18
+ lapply(Flattr_filenames ,
19
+ read.csv ,
20
+ sep = " ;" ,
21
+ dec = " ," , # convert decimal separator from , to . for following calculations
22
+ stringsAsFactors = FALSE #
23
+ )
24
+ ) # Function structure learned from https://stat.ethz.ch/pipermail/r-help/2010-October/255593.html
33
25
34
26
# append 1st days to months & convert to date format
35
27
# learned from http://stackoverflow.com/a/4594269
@@ -56,8 +48,8 @@ export_csv <- function(data_source, filename) {
56
48
sep = " ;" ,
57
49
dec = " ," ,
58
50
row.names = FALSE
59
- )}
60
-
51
+ )
52
+ }
61
53
62
54
# exports summary to same folder
63
55
export_csv(per_thing_ordered , " flattr-revenue-summary.csv" )
@@ -75,21 +67,19 @@ per_period <- ddply(raw,
75
67
76
68
# plots Flattr clicks over time
77
69
# // TODO colorize by "title"-category
78
- # // TODO spread elements out randomly over 25 days in their months (leave visible gap to next month)
79
70
per_period $ EUR_per_click <- (per_period $ all_revenue / per_period $ all_clicks )
80
71
library(ggplot2 )
81
72
qplot(x = per_period $ period ,
82
73
y = per_period $ EUR_per_click ,
83
74
xlab = " time" ,
84
75
ylab = " EUR per click"
85
76
)
86
- ggsave(" flattr-revenue-clicks.pdf " )
77
+ ggsave(" flattr-revenue-clicks.png " )
87
78
88
79
# orders by title
89
80
per_period_orderd <- per_period [order(per_period $ title ),]
90
81
91
82
# export to same folder
92
- # // TODO functionalize export with dataframe & filename objects
93
83
export_csv(per_period_orderd , " flattr-revenue-click-value.csv" )
94
84
95
85
# restore original working directory
0 commit comments