Skip to content

Commit

Permalink
Ответ в Яндекс
Browse files Browse the repository at this point in the history
  • Loading branch information
iMissile committed Sep 27, 2016
1 parent 6a1a3cc commit 75a632f
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 26 deletions.
68 changes: 42 additions & 26 deletions 52 yandex_taxi/analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,44 @@ source("funcs.R") #
# rawdata <- read_excel("./src/tv_sample.xlsx", sheet = 1, col_names = TRUE, col_types =)

# ïðîâåðèì, êàê ðàñïîçíàþòñÿ äàòû ñ ÿâíûì óêàçàíèåì òàéìçîí
dmy_hms('19.01.2015 17:52:51Z+00', truncated = 3, tz = 'Europe/Moscow')
tdate <- dmy_hms("19.01.2015 17:52:51Z+00", truncated = 3, tz = "Europe/Moscow")
tdate
with_tz(tdate, tz = "Asia/Yekaterinburg")

# îïðåäåëÿåì timezone
# http://stackoverflow.com/questions/36300381/dplyr-mutate-with-function-call-returning-incorrect-value
# http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml
get_tz <- function(m) {
case_when(m == 'Ìîñêâà' ~ 'Europe/Moscow',
m == 'Ïåðìü' ~ 'Asia/Yekaterinburg')
case_when(m == "Ìîñêâà" ~ "Europe/Moscow",
m == "Ïåðìü" ~ "Asia/Yekaterinburg")
}

# òàê ìû îáõîäèì òî, ÷òî dmy íå ïðèíèìàåò tz â âèäå âåêòîðà
get_tz_offset <- function(m) {
case_when(m == 'Ìîñêâà' ~ '+03',
m == 'Ïåðìü' ~ '+05')
case_when(m == "Ìîñêâà" ~ "+03",
m == "Ïåðìü" ~ "+05")
}

# http://barryrowlingson.github.io/hadleyverse/#5
# ñðàçó ïðåîáðàçóåì âðåìÿ
raw_tv.df <- read_delim(
'./data/tv.csv', delim = ";", quote = "\"",
"./data/tv.csv", delim = ";", quote = "\"",
col_names = TRUE,
col_types = str_c(rep('c', 18), collapse = ''),
col_types = str_c(rep("c", 18), collapse = ""),
locale = locale("ru", encoding = "windows-1251", tz = "Europe/Moscow"), # òàéìçîíó, â ïðèíöèïå, ìîæíî óñòàíîâèòü çäåñü
progress = interactive()
)

raw_installs.df <- read_delim(
'./data/installs.csv', delim = ";", quote = "\"",
col_types = 'cci',
"./data/installs.csv", delim = ";", quote = "\"",
col_types = "cci",
locale = locale("ru", encoding = "windows-1251", tz = "Europe/Moscow"), # òàéìçîíó, â ïðèíöèïå, ìîæíî óñòàíîâèòü çäåñü
progress = interactive()
)

raw_visits.df <- read_delim(
'./data/visits.csv', delim = ";", quote = "\"",
col_types = 'cciii',
"./data/visits.csv", delim = ";", quote = "\"",
col_types = "cciii",
locale = locale("ru", encoding = "windows-1251", tz = "Europe/Moscow"), # òàéìçîíó, â ïðèíöèïå, ìîæíî óñòàíîâèòü çäåñü
progress = interactive()
)
Expand All @@ -74,41 +76,55 @@ t3 <- map(raw_visits.df, unique)

# ===== ïðèâåäåì âðåìÿ â ïîðÿäîê, ìîæíî ïîäóìàòü íàñ÷åò óñòðàíåíèÿ copy-paste
raw_tv.df %<>%
mutate(timestamp = dmy_hms(str_c(local_date, local_time, 'Z', get_tz_offset(city), sep = ' '),
truncated = 3, tz = 'Europe/Moscow'))
mutate(timestamp = dmy_hms(str_c(local_date, local_time, "Z", get_tz_offset(city), sep = " "),
truncated = 3, tz = "Europe/Moscow"))
raw_installs.df %<>%
mutate(timestamp = dmy_hms(moscow_time, truncated = 3, tz = 'Europe/Moscow'))
mutate(timestamp = dmy_hms(moscow_time, truncated = 3, tz = "Europe/Moscow"))
raw_visits.df %<>%
mutate(timestamp = dmy_hms(moscow_time, truncated = 3, tz = 'Europe/Moscow'))
mutate(timestamp = dmy_hms(moscow_time, truncated = 3, tz = "Europe/Moscow"))

# select(city, local_time, local_date, timestamp)

# ===== ïîïðîáóåì âçãëÿíóòü íà äàííûå
s_date <- dmy_hm("25.01.2015 0:0", tz="Europe/Moscow")
e_date <- s_date + days(3)
# ïîëó÷àåòñÿ ãðåáåíêà, íàäî óñðåäíèòü

s_date <- dmy_hm("18.01.2015 0:0", tz="Europe/Moscow")
e_date <- s_date + days(60)

dst <- "Ïåðìü"
dst <- "Ìîñêâà"
# http://stackoverflow.com/questions/24569154/use-variable-names-in-functions-of-dplyr

subdata <- raw_installs.df %>%
filter(city == 'Ïåðìü') %>%
filter_(str_c("city == '", dst, "'")) %>%
mutate(timestamp = dmy_hms(moscow_time, truncated = 3, tz = "Europe/Moscow")) %>%
#mutate(timestamp2 = lubridate::with_tz(timestamp, tzone = 'Asia/Yekaterinburg')) %>%
# mutate_(timestamp = str_c("lubridate::with_tz(timestamp, tzone = '", get_tz(dst), "')")) %>% # ðàáîòàåò
filter(timestamp > s_date & timestamp < e_date) %>%
mutate(timegroup = hgroup.enum(timestamp, time.bin = 0.5)) %>%
mutate(timegroup = hgroup.enum(timestamp, time.bin = 1)) %>%
# ñóììèðóåì âñå èíñòàëëÿöèè
group_by(timegroup) %>%
summarise(inst = sum(installations))

subdata

tv.df <- raw_tv.df %>%
select(timestamp, city) %>%
filter_(str_c("city == '", dst, "'")) %>%
filter(timestamp > s_date & timestamp < e_date) %>%
mutate(stub = 1000)

gp <- ggplot(subdata, aes(x = timegroup, y = inst)) +
geom_point(size=2, shape=21) + # produce scatterplot
geom_point(size = 2, shape = 21) + # produce scatterplot
geom_line(lwd = 1) +
scale_x_datetime(labels = date_format_tz("%d.%m %H:%M", tz="Europe/Moscow"),
scale_x_datetime(labels = date_format_tz("%d.%m %H:%M", tz = get_tz(dst)),
#scale_x_datetime(labels = date_format_tz("%d.%m %H:%M", tz = "Europe/Moscow"),
breaks = date_breaks("4 hours"),
minor_breaks = date_breaks("30 mins")) +
theme_bw()
# äîáàâèì ñþäà äàííûå ïî ïîêàçó ðåêëàìû
geom_point(data = tv.df, mapping = aes(x = timestamp, y = stub), size = 1, color = "red") +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
gp


# ïîëó÷àåòñÿ ãðåáåíêà, íàäî óñðåäíèòü

stop()

45 changes: 45 additions & 0 deletions 52 yandex_taxi/answer/answer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
������, ������ ����.
�������� �������. � ���� ��������� ������������ ������ �� ���� ������, �� �� ������, ��� ��� ��, ��� ������ ������ ���� �����������.


1. � excel �������� �������� �����, �� �������� ������� ����������� ������, ������� ������������ � csv � ������� ������������ �������. ����� � � ����, �� ����� ���������� ������? �����, �������� � ������ ����������� ������� ��� �������� ������, ���� ���. ��������� � ��������� (�� ���-���, � ����������� �� ���������� �������� �������).
2. ��� �������� ����������� (����� ����� ��� ����������� ��� ���� ��� ����� �������), �� ������ ������������� ��� "�����" ��������.
3. ������� ������ ��� ��������� ���� ������ � ��� ������� ���� �����-���� ������ ������ ������� ����������� �����. ��������� ����� ��� ���� ���, ���� �� �������.
4. � �������� �������������� ������ ����� ���� ���������� �������. ������� -- ������� ��� �� �������� ��������. ������ ���������� ���������������� ����������, ������ ����� �������. ��� �������, ���� � ������� 5-10 ����� �� �� �������� ��������, �� ��� �������� ��� ������ ���-�� ������. � ����� ������ ���������� ����� ���������, ������������ �������, ���������� ����� ����� ��������� �����������.
5. ����������� ��� ������ �������������. ������� ������� � ������ �������� ������ �� �������, ��� �� ������, ��� �� ����� (pic_01, pic_02). ���� ���������� ������������� ������������������. ������, �� �������� ����� ����������� � �������� ����� ~ 8-23. ����� ��������, � �� ������� ������ ����� ��� ���?
6. ������� ��������� ��������� (pic_03, pic_04). ��� ����� ���������, � ��������� �� ����������.


�����, �������, ������ ��������-������������ �����, �� ����� ��� ������ ��������.
1. ��������� ���� �����������? ����� �� ���� ��� ����� ������ ������� �������: ��������, ��������, ���������� �����, ������ �����. �� ����� �� ������� �� �������� ����� ����� �� ������ � �� ������. � ����� �� �� ������� ������, �� � ������, ��� ��� �� ���������, �������� ���������� ������ ���� ����������, � �� ��? � 10 ��� ��������� ����������������� ������� � ������ �� ���������� � ����������� �������� ���������� �������������.
2. ���������� ������������� ������, ����� ���������� ��������� � �������� (��������� ��������). ����� ��������������� �������� �������� ��� ������������ �������, ��������� ������� �� ������� � ������� ����������� ���������? ��� ��� ������?
3. ��� ���������� ������.�����? ���� ������� �����������? ���� �� 16? ���. ����������? ������ �����������. ����, ������� �� ���������� �� ��? �� ������ �� ���.
� ��� ������� ��������� � 9 �� 19? ������ �������������� ����������. ��� ���������������� ��������� � ��� ����� �� ������\�������, � �����.
4. ��� ������� ��������� � ��������� � �����? ���� ���� ������� ������ ������� � ����������, ��� ���� �������� � �������, ����� �������, ��������� appstore\google play, ������, ���-�� �������.... ����� ����� �������� ����� �������� ���? (� 22-23, ����� ���� ����� � �������?). � ���� � ���� � ����� �������\�������, ��, ������ �����, �� � ��������� � ��������� ������ �����.
5. ����� � ������ ��������� ������� ���� � ����������� �������� ��� ������������� ����. � ������� ������ ������������� ��������. ����������� ��������� ���� �������� �����. ����� ��� ������� -- ��, �� � ������\���� �������. � ��-�����������, � ������ ���������� ��� ������, ������ �� ������������ ���� ��� ���������.
��� �������� �������������� ������� ���������.
6. ���� ��������� �� �������, �� ������� ���������� ������, ��� ������� ������ ����� �����������? �������� ������? ��������������? ��������, ��� ������� ������ ����� � �������� ����� ������� � 1.5-2 ����, ��� ������������ �������� ������� ���������. ��� �� ��� �� ���������. ���� 1-2 ����� ������ �������� ����� ��������� ���������� � ��������������� �������.

�� ��� ������, ��������, ��� �� ������� �������, �������� ��������������.
���� �� � ���������, �� ����� ������ � ����� ����� (6-8) � ������� (8-24).
����� ��������� ������������ ����� � ��������� ������ �� ������:
- �������� � ������� � ���������� � ��������.
- ������� � ���������� � ������ ������.
- �������� �� �����������\�������� �����������. ���� ��� ����� �� ����� � �������, ���� ����� ��������� � ����.
- ������� � ���������.
- ������� �� ���������.
- ������� �� ����� 7-10, 18-20 (������ ������������� ����������� ����� �� ������ �� ������ � ������� ������ �����, � �� ��) (��. ����� "Working Girl"! :) ).
- ���� ��� ��� �����, ������� � ������ ���� �� ��������������� �������, �� �� ������ �� �����������. ���� ������� ������� � ������� ������� ���������, ������ ������������� ���������� �� ������� ��� ������ ���������� ������ ��������� � �������� ��� ������������ (������������ �� ������ �������), �� ����� ���� �� � ���� ����� ���������.

�� ����, ����� ����� �������� �� ��� ������, �� �����������, ��� ������� ������� ������������� �������� ����������� � ���������.
� ��������, ���� � �������� ������� ������ ������������� �������, ���� ���� ������ ���������, �� ����� ����������� ������������ ��������� �������� �����.
������ �����-�����, ������������� �� �������� � ��.
�������� ����� � �� ����������, �� ����������� ����������� ������ ��� ��������� ������� ��� ������� ������������������.

�����������.
pic_01 -- ������ ����������� �� ������ �� ���� ������, ��������� ���������, �������� ����� ������ ������� � ������
pic_02 -- ������ ����������� �� ����� �� ���� ������, 2-� ������� ���������, �������� ����� ������ ������� � �����
pic_03 -- ������ ����������� �� ������ �� 7 ����, ��������� ���������, �������� ����� ������ ������� � ������
pic_04 -- ������ ����������� �� ����� �� 7 ����, ��������� ���������, �������� ����� ������ ������� � �����

����
Binary file added 52 yandex_taxi/answer/pic_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 52 yandex_taxi/answer/pic_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 52 yandex_taxi/answer/pic_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 52 yandex_taxi/answer/pic_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 75a632f

Please sign in to comment.