c80_estate 0.1.0.3 → 0.1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/admin/c80_estate/dashboard.rb +65 -0
- data/app/admin/c80_estate/properties.rb +9 -1
- data/app/admin/c80_estate/sevents.rb +18 -12
- data/app/assets/images/property_default_logo.png +0 -0
- data/app/assets/javascript/c80_estate/backend/admin/pstats.js +231 -40
- data/app/assets/javascript/c80_estate/backend/admin/sevents.js +127 -1
- data/app/assets/javascript/c80_estate/lib/Chart.bundle.js +14282 -0
- data/app/assets/javascript/c80_estate/lib/jquery.canvasjs.min.js +560 -0
- data/app/assets/stylesheets/c80_estate/backend/admin_pstats.scss +55 -5
- data/app/assets/stylesheets/c80_estate/backend/admin_sevents.scss +5 -0
- data/app/assets/stylesheets/c80_estate/backend/dashboard/atype_in_list.scss +29 -0
- data/app/assets/stylesheets/c80_estate/backend/dashboard/common.scss +43 -0
- data/app/assets/stylesheets/c80_estate/backend/dashboard/prop_in_list.scss +52 -0
- data/app/controllers/c80_estate/ajax_view_controller.rb +23 -0
- data/app/helpers/c80_estate/app_helper.rb +55 -0
- data/app/models/c80_estate/area.rb +40 -15
- data/app/models/c80_estate/plogo.rb +6 -0
- data/app/models/c80_estate/pphoto.rb +1 -0
- data/app/models/c80_estate/property.rb +14 -0
- data/app/models/c80_estate/pstat.rb +419 -30
- data/app/models/c80_estate/sevent.rb +65 -1
- data/app/uploaders/c80_estate/plogo_uploader.rb +25 -0
- data/app/views/admin/dashboard/_atype_in_list.html.erb +3 -0
- data/app/views/admin/dashboard/_prop_in_list.html.erb +10 -0
- data/app/views/c80_estate/ajax_view/table_properties_coef_busy.js.erb +3 -0
- data/app/views/c80_estate/ajax_view/table_properties_coef_busy_sq.js.erb +3 -0
- data/app/views/c80_estate/shared/_table_properties_coef_busy.html.erb +25 -0
- data/app/views/c80_estate/shared/_table_properties_coef_busy_sq.html.erb +25 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20160630012728_create_c80_estate_plogos.rb +9 -0
- data/lib/c80_estate/version.rb +1 -1
- metadata +20 -2
@@ -10,6 +10,8 @@ module C80Estate
|
|
10
10
|
belongs_to :parent, :class_name => 'C80Estate::Pstat'
|
11
11
|
has_many :pstats, :foreign_key => 'parent_id', :dependent => :destroy
|
12
12
|
|
13
|
+
scope :ordered_by_created_at, -> { order(created_at: :asc) }
|
14
|
+
|
13
15
|
# рассчитаем коэф-ты занятости
|
14
16
|
before_create :calc_busy_coefs
|
15
17
|
|
@@ -18,34 +20,108 @@ module C80Estate
|
|
18
20
|
|
19
21
|
def self.busy_coef(prop_id: nil, atype_id: nil, start_date: nil, end_date: nil)
|
20
22
|
# start_date: строка вида 2015-12-12
|
21
|
-
|
23
|
+
# Rails.logger.debug "<Pstat.busy_coef> prop_id = #{prop_id}, atype_id = #{atype_id}"
|
22
24
|
result = {}
|
23
25
|
|
26
|
+
# обозначим диапазон фильтрации
|
27
|
+
first_created_at = Time.at(self.first.created_at)
|
28
|
+
time_now = Time.now
|
29
|
+
|
24
30
|
# если ничего не подано - просто выберем все занятые площади и поделим на все известные площади
|
25
|
-
if prop_id.nil? && atype_id.nil?
|
31
|
+
if prop_id.nil? && atype_id.nil?
|
32
|
+
|
33
|
+
# prepare
|
26
34
|
|
27
|
-
|
28
|
-
free_areas_count = Area.free_areas.count
|
29
|
-
busy_areas_count = Area.busy_areas.count
|
35
|
+
tcut = _calc_time_cut(first_created_at, time_now, start_date, end_date)
|
30
36
|
|
31
37
|
ddd = '-'
|
32
38
|
if self.count > 0
|
33
|
-
ddd = Time.at(self.first.created_at).strftime('%Y/%m/%d')
|
39
|
+
ddd = tcut[:used_start_date_str] #Time.at(self.first.created_at).strftime('%Y/%m/%d')
|
34
40
|
end
|
35
41
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
42
|
+
pstats = self.where("created_at BETWEEN ? AND ?", tcut[:used_start_date], tcut[:used_end_date])
|
43
|
+
.where(:atype_id => nil)
|
44
|
+
|
45
|
+
# если в этот промежуток небыло событий - значит промежуток целиком попал в какое-то событие
|
46
|
+
# найдем его
|
47
|
+
# заодно поднимем вспомогательный флаг, который обработаем во view
|
48
|
+
mark_whole = false
|
49
|
+
if pstats.count == 0
|
50
|
+
pstats = [self.where(:atype_id => nil).where("created_at < ?", tcut[:used_start_date]).last]
|
51
|
+
mark_whole = true
|
52
|
+
# sevents.each do |se|
|
53
|
+
# Rails.logger.debug "\t\t\t #{used_start_date - se.created_at}"
|
54
|
+
# end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Занятость
|
58
|
+
|
59
|
+
tt = _calc_free_busy_areas(pstats)
|
60
|
+
|
61
|
+
free_areas_atnow = tt[:sum_free_areas] #*1.0/all_props.count #pstats.last.free_areas
|
62
|
+
busy_areas_atnow = tt[:sum_busy_areas] #*1.0/all_props.count #pstats.last.busy_areas
|
63
|
+
graph_data = _parse_for_js_dynamic_graph_canvasjs(pstats.ordered_by_created_at)
|
64
|
+
|
65
|
+
# защищаемся от деления на ноль
|
66
|
+
if free_areas_atnow + busy_areas_atnow == 0
|
67
|
+
bcoef = 0.0
|
68
|
+
else
|
69
|
+
bcoef = busy_areas_atnow*1.0 / (free_areas_atnow + busy_areas_atnow) * 100.0
|
70
|
+
end
|
71
|
+
|
72
|
+
# all_areas_count = Area.all.count
|
73
|
+
# free_areas_count = Area.free_areas.count
|
74
|
+
# busy_areas_count = Area.busy_areas.count
|
75
|
+
|
76
|
+
result[:busy_coef] = sprintf "%.2f%", bcoef
|
77
|
+
result[:comment] = "<abbr title='Период рассчёта занятости'>C #{ddd} по #{ tcut[:used_end_date_str] }</abbr>"
|
78
|
+
result[:abbr] = 'Показана занятость для ВСЕХ площадей ВСЕХ объектов недвижимости за указанный период'
|
40
79
|
result[:props] = [
|
41
|
-
{tag: 'all_areas_count', val: "Площадей всего: #{
|
42
|
-
{tag: 'free_areas_count', val: "Площадей свободно: #{
|
43
|
-
{tag: 'busy_areas_count', val: "Площадей занято: #{
|
80
|
+
{tag: 'all_areas_count', val: "Площадей всего: #{free_areas_atnow + busy_areas_atnow}"},
|
81
|
+
{tag: 'free_areas_count', val: "Площадей свободно: #{free_areas_atnow}"},
|
82
|
+
{tag: 'busy_areas_count', val: "Площадей занято: #{busy_areas_atnow}"}
|
83
|
+
]
|
84
|
+
result[:raw_props] = {}
|
85
|
+
result[:raw_props][:all_areas_count] = free_areas_atnow + busy_areas_atnow
|
86
|
+
result[:raw_props][:free_areas_count] = free_areas_atnow
|
87
|
+
result[:raw_props][:busy_areas_atnow] = busy_areas_atnow
|
88
|
+
result[:graph_dynamic] = graph_data
|
89
|
+
|
90
|
+
# Rails.logger.debug "<Pstat.busy_coef> busy_areas_count = #{ busy_areas_count }"
|
91
|
+
# Rails.logger.debug "<Pstat.busy_coef> all_areas_count = #{ all_areas_count }"
|
92
|
+
# Rails.logger.debug "<Pstat.busy_coef> result[:busy_coef] = #{ result[:busy_coef] }"
|
93
|
+
|
94
|
+
# Занятость в метрах
|
95
|
+
|
96
|
+
free_areas_atnow_sq = pstats.where(:atype_id => nil).last.free_areas_sq
|
97
|
+
busy_areas_atnow_sq = pstats.where(:atype_id => nil).last.busy_areas_sq
|
98
|
+
graph_data_sq = _parse_for_js_dynamic_graph3_canvasjs(pstats.where(:atype_id => nil).ordered_by_created_at)
|
99
|
+
|
100
|
+
# защищаемся от деления на ноль
|
101
|
+
if busy_areas_atnow_sq + free_areas_atnow_sq == 0
|
102
|
+
bcoef_sq = 0.0
|
103
|
+
else
|
104
|
+
bcoef_sq = busy_areas_atnow_sq*1.0/(busy_areas_atnow_sq + free_areas_atnow_sq)*100.0
|
105
|
+
end
|
106
|
+
|
107
|
+
result[:busy_coef_sq] = sprintf "%.2f%", bcoef_sq
|
108
|
+
result[:comment_sq] = "<abbr title='Период рассчёта занятости в МЕТРАХ КВ'>C #{tcut[:used_start_date_str]} по #{tcut[:used_end_date_str]}</abbr>"
|
109
|
+
result[:abbr_sq] = 'Занятость объекта в МЕТРАХ за указанный период: число b/N, где b - кол-во свободных МЕТРОВ, N - всего МЕТРОВ КВ'
|
110
|
+
result[:props_sq] = [
|
111
|
+
{tag: 'all_areas_count_sq', val: "Кв.м. всего: #{busy_areas_atnow_sq + free_areas_atnow_sq}"},
|
112
|
+
{tag: 'free_areas_count_sq', val: "Свободных: #{free_areas_atnow_sq}"},
|
113
|
+
{tag: 'busy_areas_count_sq', val: "Занятых: #{busy_areas_atnow_sq}"}
|
44
114
|
]
|
115
|
+
result[:raw_props_sq] = {}
|
116
|
+
result[:raw_props_sq][:all_areas_count_sq] = free_areas_atnow_sq + busy_areas_atnow_sq
|
117
|
+
result[:raw_props_sq][:free_areas_count_sq] = free_areas_atnow_sq
|
118
|
+
result[:raw_props_sq][:busy_areas_atnow_sq] = busy_areas_atnow_sq
|
119
|
+
result[:graph_dynamic_sq] = graph_data_sq
|
120
|
+
|
121
|
+
# common
|
45
122
|
|
46
|
-
|
47
|
-
Rails.logger.debug "
|
48
|
-
Rails.logger.debug "<Pstat.busy_coef> result[:busy_coef] = #{ result[:busy_coef] }"
|
123
|
+
result[:title] = 'Статистика - Все объекты недвижимости'
|
124
|
+
# Rails.logger.debug "result ============= #{result}"
|
49
125
|
|
50
126
|
# если фильтруем по property
|
51
127
|
elsif prop_id.present?
|
@@ -115,19 +191,23 @@ module C80Estate
|
|
115
191
|
# end
|
116
192
|
end
|
117
193
|
|
194
|
+
# Занятость -----
|
195
|
+
|
118
196
|
# если сортируем по типу, то берём последнюю запись,
|
119
197
|
# иначе - берём последнюю запись с общими данными
|
120
198
|
if atype_id.nil?
|
121
199
|
free_areas_atnow = pstats.where(:atype_id => nil).last.free_areas
|
122
200
|
busy_areas_atnow = pstats.where(:atype_id => nil).last.busy_areas
|
201
|
+
graph_data = _parse_for_js_dynamic_graph_canvasjs(pstats.where(:atype_id => nil).ordered_by_created_at)
|
123
202
|
else
|
124
203
|
free_areas_atnow = pstats.last.free_areas
|
125
204
|
busy_areas_atnow = pstats.last.busy_areas
|
205
|
+
graph_data = _parse_for_js_dynamic_graph_canvasjs(pstats.ordered_by_created_at)
|
126
206
|
end
|
127
207
|
|
128
|
-
Rails.logger.debug("\t\t atype_id = #{atype_id}")
|
129
|
-
Rails.logger.debug("\t\t free_areas_atnow = #{free_areas_atnow}")
|
130
|
-
Rails.logger.debug("\t\t busy_areas_atnow = #{busy_areas_atnow}")
|
208
|
+
# Rails.logger.debug("\t\t atype_id = #{atype_id}")
|
209
|
+
# Rails.logger.debug("\t\t free_areas_atnow = #{free_areas_atnow}")
|
210
|
+
# Rails.logger.debug("\t\t busy_areas_atnow = #{busy_areas_atnow}")
|
131
211
|
|
132
212
|
# защищаемся от деления на ноль
|
133
213
|
if free_areas_atnow + busy_areas_atnow == 0
|
@@ -138,10 +218,52 @@ module C80Estate
|
|
138
218
|
|
139
219
|
result[:busy_coef] = sprintf "%.2f%", bcoef
|
140
220
|
result[:comment] = "<abbr title='Период рассчёта занятости'>C #{used_start_date_str} по #{used_end_date_str}</abbr>"
|
141
|
-
result[:abbr] = 'Занятость объекта за указанный
|
221
|
+
result[:abbr] = 'Занятость объекта за указанный период: число b/N, где b - кол-во свободных, N - всего площадей'
|
222
|
+
|
223
|
+
result[:raw_props] = {}
|
224
|
+
result[:raw_props][:all_areas_count] = free_areas_atnow + busy_areas_atnow
|
225
|
+
result[:raw_props][:free_areas_count] = free_areas_atnow
|
226
|
+
result[:raw_props][:busy_areas_atnow] = busy_areas_atnow
|
227
|
+
|
228
|
+
# Занятость в метрах ------
|
229
|
+
|
230
|
+
if atype_id.nil?
|
231
|
+
free_areas_atnow_sq = pstats.where(:atype_id => nil).last.free_areas_sq
|
232
|
+
busy_areas_atnow_sq = pstats.where(:atype_id => nil).last.busy_areas_sq
|
233
|
+
graph_data_sq = _parse_for_js_dynamic_graph3_canvasjs(pstats.where(:atype_id => nil).ordered_by_created_at)
|
234
|
+
else
|
235
|
+
free_areas_atnow_sq = pstats.last.free_areas_sq
|
236
|
+
busy_areas_atnow_sq = pstats.last.busy_areas_sq
|
237
|
+
graph_data_sq = _parse_for_js_dynamic_graph3_canvasjs(pstats.ordered_by_created_at)
|
238
|
+
end
|
239
|
+
|
240
|
+
# защищаемся от деления на ноль
|
241
|
+
if busy_areas_atnow_sq + free_areas_atnow_sq == 0
|
242
|
+
bcoef_sq = 0.0
|
243
|
+
else
|
244
|
+
bcoef_sq = busy_areas_atnow_sq*1.0/(busy_areas_atnow_sq + free_areas_atnow_sq)*100.0
|
245
|
+
end
|
246
|
+
|
247
|
+
result[:busy_coef_sq] = sprintf "%.2f%", bcoef_sq
|
248
|
+
result[:comment_sq] = "<abbr title='Период рассчёта занятости в МЕТРАХ КВ'>C #{used_start_date_str} по #{used_end_date_str}</abbr>"
|
249
|
+
result[:abbr_sq] = 'Занятость объекта в МЕТРАХ за указанный период: число b/N, где b - кол-во свободных МЕТРОВ, N - всего МЕТРОВ КВ'
|
250
|
+
result[:props_sq] = [
|
251
|
+
{tag: 'all_areas_count_sq', val: "Кв.м. всего: #{busy_areas_atnow_sq + free_areas_atnow_sq}"},
|
252
|
+
{tag: 'free_areas_count_sq', val: "Свободных: #{free_areas_atnow_sq}"},
|
253
|
+
{tag: 'busy_areas_count_sq', val: "Занятых: #{busy_areas_atnow_sq}"}
|
254
|
+
]
|
255
|
+
|
256
|
+
result[:raw_props_sq] = {}
|
257
|
+
result[:raw_props_sq][:all_areas_count_sq] = free_areas_atnow_sq + busy_areas_atnow_sq
|
258
|
+
result[:raw_props_sq][:free_areas_count_sq] = free_areas_atnow_sq
|
259
|
+
result[:raw_props_sq][:busy_areas_atnow_sq] = busy_areas_atnow_sq
|
260
|
+
|
261
|
+
# common
|
262
|
+
|
142
263
|
result[:title] = "Статистика - Объект - #{property.title}"
|
143
|
-
result[:graph] = _parse_for_js_radial_graph(free_areas_atnow,busy_areas_atnow)
|
144
|
-
result[:graph_dynamic] =
|
264
|
+
# result[:graph] = _parse_for_js_radial_graph(free_areas_atnow,busy_areas_atnow)
|
265
|
+
result[:graph_dynamic] = graph_data
|
266
|
+
result[:graph_dynamic_sq] = graph_data_sq
|
145
267
|
|
146
268
|
# if atype_id.present?
|
147
269
|
# result[:title] += " (#{Atype.find(atype_id).title})"
|
@@ -167,6 +289,142 @@ module C80Estate
|
|
167
289
|
{tag: 'title', val: "#{property.title} не имеет площадей"}
|
168
290
|
]
|
169
291
|
end
|
292
|
+
|
293
|
+
elsif atype_id.present?
|
294
|
+
|
295
|
+
# обозначим диапазон фильтрации
|
296
|
+
first_created_at = Time.at(self.first.created_at)
|
297
|
+
time_now = Time.now
|
298
|
+
|
299
|
+
# если подана нижняя граница диапазона и она позже, чем время создания самой первой площади объекта,
|
300
|
+
# выравниваем период рассчета коэф-та по этой нижней границе диапазона
|
301
|
+
if start_date.present?
|
302
|
+
start_date_tt = Time.parse(start_date)
|
303
|
+
if start_date_tt > first_created_at
|
304
|
+
used_start_date = start_date_tt
|
305
|
+
# Rails.logger.debug("start_date: используем аргумент: #{start_date_tt}")
|
306
|
+
else
|
307
|
+
used_start_date = first_created_at
|
308
|
+
# Rails.logger.debug("start_date: используем время рождения Площади: #{area_created_at}")
|
309
|
+
end
|
310
|
+
else
|
311
|
+
used_start_date = first_created_at
|
312
|
+
# Rails.logger.debug("start_date: используем время рождения Площади: #{area_created_at}")
|
313
|
+
end
|
314
|
+
used_start_date_str = used_start_date.strftime('%Y/%m/%d')
|
315
|
+
|
316
|
+
if end_date.present?
|
317
|
+
end_date_tt = Time.parse(end_date)
|
318
|
+
if end_date < time_now
|
319
|
+
used_end_date = end_date_tt
|
320
|
+
# Rails.logger.debug("end_date: используем аргумент: #{end_date_tt}")
|
321
|
+
else
|
322
|
+
used_end_date = time_now
|
323
|
+
# Rails.logger.debug("end_date: используем текущее время")
|
324
|
+
end
|
325
|
+
else
|
326
|
+
used_end_date = time_now
|
327
|
+
# Rails.logger.debug("end_date: используем текущее время")
|
328
|
+
end
|
329
|
+
used_end_date_str = used_end_date.strftime('%Y/%m/%d')
|
330
|
+
|
331
|
+
# Rails.logger.debug("start_date = #{start_date}; end_date = #{end_date}; used_start_date = #{used_start_date}; used_end_date = #{used_end_date}")
|
332
|
+
# sevents = self.where(:area_id => area_id).where(:created_at => used_start_date..used_end_date)
|
333
|
+
pstats = self.where(:atype_id => atype_id)
|
334
|
+
.where("created_at BETWEEN ? AND ?", used_start_date, used_end_date)
|
335
|
+
|
336
|
+
|
337
|
+
# если в этот промежуток небыло событий - значит промежуток целиком попал в какое-то событие
|
338
|
+
# найдем его
|
339
|
+
# заодно поднимем вспомогательный флаг, который обработаем во view
|
340
|
+
mark_whole = false
|
341
|
+
if pstats.count == 0
|
342
|
+
pstats = [self.where(:atype_id => atype_id).where("created_at < ?", used_start_date).last]
|
343
|
+
mark_whole = true
|
344
|
+
# sevents.each do |se|
|
345
|
+
# Rails.logger.debug "\t\t\t #{used_start_date - se.created_at}"
|
346
|
+
# end
|
347
|
+
end
|
348
|
+
|
349
|
+
# Занятость
|
350
|
+
|
351
|
+
tt = _calc_free_busy_areas(pstats)
|
352
|
+
|
353
|
+
free_areas_atnow = tt[:sum_free_areas] #*1.0/all_props.count #pstats.last.free_areas
|
354
|
+
busy_areas_atnow = tt[:sum_busy_areas] #*1.0/all_props.count #pstats.last.busy_areas
|
355
|
+
graph_data = _parse_for_js_dynamic_graph_canvasjs(pstats.ordered_by_created_at)
|
356
|
+
|
357
|
+
# Rails.logger.debug("\t\t atype_id = #{atype_id}")
|
358
|
+
# Rails.logger.debug("\t\t free_areas_atnow = #{free_areas_atnow}")
|
359
|
+
# Rails.logger.debug("\t\t busy_areas_atnow = #{busy_areas_atnow}")
|
360
|
+
|
361
|
+
# защищаемся от деления на ноль
|
362
|
+
if free_areas_atnow + busy_areas_atnow == 0
|
363
|
+
bcoef = 0.0
|
364
|
+
else
|
365
|
+
bcoef = busy_areas_atnow*1.0 / (free_areas_atnow + busy_areas_atnow) * 100.0
|
366
|
+
end
|
367
|
+
|
368
|
+
result[:busy_coef] = sprintf "%.2f%", bcoef
|
369
|
+
result[:comment] = "<abbr title='Период рассчёта занятости'>C #{used_start_date_str} по #{used_end_date_str}</abbr>"
|
370
|
+
result[:abbr] = 'Занятость объекта за указанный период: число b/N, где b - кол-во свободных, N - всего площадей'
|
371
|
+
|
372
|
+
result[:raw_props] = {}
|
373
|
+
result[:raw_props][:all_areas_count] = free_areas_atnow + busy_areas_atnow
|
374
|
+
result[:raw_props][:free_areas_count] = free_areas_atnow
|
375
|
+
result[:raw_props][:busy_areas_atnow] = busy_areas_atnow
|
376
|
+
|
377
|
+
# Занятость в метрах
|
378
|
+
|
379
|
+
free_areas_atnow_sq = pstats.last.free_areas_sq
|
380
|
+
busy_areas_atnow_sq = pstats.last.busy_areas_sq
|
381
|
+
graph_data_sq = _parse_for_js_dynamic_graph3_canvasjs(pstats.ordered_by_created_at)
|
382
|
+
|
383
|
+
# защищаемся от деления на ноль
|
384
|
+
if busy_areas_atnow_sq + free_areas_atnow_sq == 0
|
385
|
+
bcoef_sq = 0.0
|
386
|
+
else
|
387
|
+
bcoef_sq = busy_areas_atnow_sq*1.0/(busy_areas_atnow_sq + free_areas_atnow_sq)*100.0
|
388
|
+
end
|
389
|
+
|
390
|
+
result[:busy_coef_sq] = sprintf "%.2f%", bcoef_sq
|
391
|
+
result[:comment_sq] = "<abbr title='Период рассчёта занятости в МЕТРАХ КВ'>C #{used_start_date_str} по #{used_end_date_str}</abbr>"
|
392
|
+
result[:abbr_sq] = 'Занятость объекта в МЕТРАХ за указанный период: число b/N, где b - кол-во свободных МЕТРОВ, N - всего МЕТРОВ КВ'
|
393
|
+
result[:props_sq] = [
|
394
|
+
{tag: 'all_areas_count_sq', val: "Кв.м. всего: #{busy_areas_atnow_sq + free_areas_atnow_sq}"},
|
395
|
+
{tag: 'free_areas_count_sq', val: "Свободных: #{free_areas_atnow_sq}"},
|
396
|
+
{tag: 'busy_areas_count_sq', val: "Занятых: #{busy_areas_atnow_sq}"}
|
397
|
+
]
|
398
|
+
|
399
|
+
result[:raw_props_sq] = {}
|
400
|
+
result[:raw_props_sq][:all_areas_count_sq] = free_areas_atnow_sq + busy_areas_atnow_sq
|
401
|
+
result[:raw_props_sq][:free_areas_count_sq] = free_areas_atnow_sq
|
402
|
+
result[:raw_props_sq][:busy_areas_atnow_sq] = busy_areas_atnow_sq
|
403
|
+
|
404
|
+
# common
|
405
|
+
|
406
|
+
result[:title] = "Статистика - Объекты - Фильтр по типу площади '#{ Atype.find(atype_id).title }'"
|
407
|
+
# result[:graph] = _parse_for_js_radial_graph(free_areas_atnow,busy_areas_atnow)
|
408
|
+
result[:graph_dynamic] = graph_data
|
409
|
+
result[:graph_dynamic_sq] = graph_data_sq
|
410
|
+
|
411
|
+
# if atype_id.present?
|
412
|
+
# result[:title] += " (#{Atype.find(atype_id).title})"
|
413
|
+
# end
|
414
|
+
|
415
|
+
dc_str = self.first.created_at.in_time_zone('Moscow').strftime('%Y/%m/%d')
|
416
|
+
dc_abbr = 'За дату создания объекта недвижимости при рассчетах берётся дата создания первой площади объекта'
|
417
|
+
|
418
|
+
result[:props] = [
|
419
|
+
{tag: 'title', val: "Фильтр по типу площади: #{ Atype.find(atype_id).title }"},
|
420
|
+
# {tag: 'born_date', val: "<abbr title='#{dc_abbr}'>Дата создания: #{dc_str}"},
|
421
|
+
{tag: 'all_areas_count', val: "<abbr title='В конце указанного периода'>Площадей всего</abbr>: #{ free_areas_atnow + busy_areas_atnow }"},
|
422
|
+
{tag: 'free_areas_count', val: "<abbr title='В конце указанного периода'>Свободных площадей</abbr>: #{ free_areas_atnow }"},
|
423
|
+
{tag: 'busy_areas_count', val: "<abbr title='В конце указанного периода'>Занятых площадей</abbr>: #{ busy_areas_atnow }"}
|
424
|
+
]
|
425
|
+
|
426
|
+
# Rails.logger.debug "result ============= #{result}"
|
427
|
+
|
170
428
|
end
|
171
429
|
|
172
430
|
result
|
@@ -200,21 +458,21 @@ module C80Estate
|
|
200
458
|
|
201
459
|
self.free_areas = self.property.areas.free_areas.count
|
202
460
|
self.busy_areas = self.property.areas.busy_areas.count
|
203
|
-
self.coef_busy = self.busy_areas / (self.free_areas + self.busy_areas) * 100
|
461
|
+
self.coef_busy = self.busy_areas*1.0 / (self.free_areas + self.busy_areas) * 100.0
|
204
462
|
|
205
463
|
self.free_areas_sq = self.property.areas.free_areas_sq
|
206
464
|
self.busy_areas_sq = self.property.areas.busy_areas_sq
|
207
|
-
self.coef_busy_sq = self.busy_areas_sq / (self.free_areas_sq + self.busy_areas_sq) * 100
|
465
|
+
self.coef_busy_sq = self.busy_areas_sq*1.0 / (self.free_areas_sq + self.busy_areas_sq) * 100.0
|
208
466
|
|
209
|
-
|
467
|
+
# здесь считаем коэф-ты для 'atype related записей'
|
210
468
|
else
|
211
469
|
self.free_areas = self.property.areas.where(:atype_id => self.atype.id).free_areas.count
|
212
470
|
self.busy_areas = self.property.areas.where(:atype_id => self.atype.id).busy_areas.count
|
213
|
-
self.coef_busy = (self.free_areas + self.busy_areas == 0) ? 0:self.busy_areas / (self.free_areas + self.busy_areas) * 100
|
471
|
+
self.coef_busy = (self.free_areas + self.busy_areas == 0) ? 0 : self.busy_areas*1.0 / (self.free_areas + self.busy_areas) * 100.0
|
214
472
|
|
215
473
|
self.free_areas_sq = self.property.areas.where(:atype_id => self.atype.id).free_areas_sq
|
216
474
|
self.busy_areas_sq = self.property.areas.where(:atype_id => self.atype.id).busy_areas_sq
|
217
|
-
self.coef_busy_sq = (self.free_areas_sq + self.busy_areas_sq == 0) ? 0:self.busy_areas_sq / (self.free_areas_sq + self.busy_areas_sq) * 100
|
475
|
+
self.coef_busy_sq = (self.free_areas_sq + self.busy_areas_sq == 0) ? 0 : self.busy_areas_sq*1.0 / (self.free_areas_sq + self.busy_areas_sq) * 100.0
|
218
476
|
end
|
219
477
|
end
|
220
478
|
end
|
@@ -260,7 +518,7 @@ module C80Estate
|
|
260
518
|
# ['Занято', 2]
|
261
519
|
# ]
|
262
520
|
|
263
|
-
res = [['','']]
|
521
|
+
res = [['', '']]
|
264
522
|
res << ['Свободно', free_areas_atnow]
|
265
523
|
res << ['Занято', busy_areas_atnow]
|
266
524
|
Rails.logger.debug "<_parse_for_js_radial_graph> res: #{res}"
|
@@ -268,7 +526,29 @@ module C80Estate
|
|
268
526
|
|
269
527
|
end
|
270
528
|
|
271
|
-
def self.
|
529
|
+
def self._parse_for_js_dynamic_graph_chartjs(pstats)
|
530
|
+
|
531
|
+
# res = {
|
532
|
+
# labels: ['2016/12/22',...]
|
533
|
+
# points: [12,13,...]
|
534
|
+
# }
|
535
|
+
|
536
|
+
res = {
|
537
|
+
labels: [],
|
538
|
+
points: []
|
539
|
+
}
|
540
|
+
pstats.each do |pstat|
|
541
|
+
label = pstat.created_at.strftime('%Y/%m/%d')
|
542
|
+
point = pstat.coef_busy
|
543
|
+
res[:labels] << label
|
544
|
+
res[:points] << point
|
545
|
+
Rails.logger.debug "<_parse_for_js_dynamic_graph_chartjs> label = #{label}, point = #{point}"
|
546
|
+
end
|
547
|
+
res
|
548
|
+
|
549
|
+
end
|
550
|
+
|
551
|
+
def self._parse_for_js_dynamic_graph_google_charts(pstats)
|
272
552
|
# res = [
|
273
553
|
# ['Year', 'Sales', 'Expenses'],
|
274
554
|
# ['2013', 1000, 400],
|
@@ -279,10 +559,119 @@ module C80Estate
|
|
279
559
|
|
280
560
|
res = []
|
281
561
|
pstats.each do |pstat|
|
282
|
-
res << [
|
562
|
+
res << [pstat.created_at.strftime('%Y/%m/%d'), pstat.coef_busy]
|
563
|
+
end
|
564
|
+
res
|
565
|
+
|
566
|
+
end
|
567
|
+
|
568
|
+
def self._parse_for_js_dynamic_graph_canvasjs(pstats)
|
569
|
+
# res: [
|
570
|
+
# {
|
571
|
+
# year
|
572
|
+
# month
|
573
|
+
# day
|
574
|
+
# val
|
575
|
+
# }
|
576
|
+
# ]
|
577
|
+
|
578
|
+
res = []
|
579
|
+
|
580
|
+
pstats.each do |pstat|
|
581
|
+
|
582
|
+
res << {
|
583
|
+
year: pstat.created_at.strftime('%Y'),
|
584
|
+
month: pstat.created_at.strftime('%m').to_i-1,
|
585
|
+
day: pstat.created_at.strftime('%d'),
|
586
|
+
val: pstat.coef_busy
|
587
|
+
}
|
588
|
+
|
589
|
+
end
|
590
|
+
|
591
|
+
Rails.logger.debug "<Pstat.parse_for_js_graph> res = #{res}"
|
592
|
+
res
|
593
|
+
end
|
594
|
+
|
595
|
+
def self._parse_for_js_dynamic_graph3_canvasjs(pstats)
|
596
|
+
# res: [
|
597
|
+
# {
|
598
|
+
# year
|
599
|
+
# month
|
600
|
+
# day
|
601
|
+
# val
|
602
|
+
# }
|
603
|
+
# ]
|
604
|
+
|
605
|
+
res = []
|
606
|
+
|
607
|
+
pstats.each do |pstat|
|
608
|
+
|
609
|
+
res << {
|
610
|
+
year: pstat.created_at.strftime('%Y'),
|
611
|
+
month: pstat.created_at.strftime('%m').to_i-1,
|
612
|
+
day: pstat.created_at.strftime('%d'),
|
613
|
+
val: pstat.coef_busy_sq
|
614
|
+
}
|
283
615
|
end
|
284
616
|
res
|
617
|
+
end
|
618
|
+
|
619
|
+
def self._calc_time_cut(first_created_at, time_now, start_date, end_date)
|
620
|
+
|
621
|
+
# если подана нижняя граница диапазона и она позже, чем время создания самой первой площади объекта,
|
622
|
+
# выравниваем период рассчета коэф-та по этой нижней границе диапазона
|
623
|
+
if start_date.present?
|
624
|
+
start_date_tt = Time.parse(start_date)
|
625
|
+
if start_date_tt > first_created_at
|
626
|
+
used_start_date = start_date_tt
|
627
|
+
# Rails.logger.debug("1: start_date: используем аргумент: #{start_date_tt} (first_created_at = #{first_created_at})")
|
628
|
+
else
|
629
|
+
used_start_date = first_created_at
|
630
|
+
# Rails.logger.debug("2: start_date: используем first_created_at: #{first_created_at}")
|
631
|
+
end
|
632
|
+
else
|
633
|
+
used_start_date = first_created_at
|
634
|
+
# Rails.logger.debug("3: start_date: используем first_created_at: #{first_created_at} (start_date = #{start_date})")
|
635
|
+
end
|
636
|
+
used_start_date_str = used_start_date.strftime('%Y/%m/%d')
|
285
637
|
|
638
|
+
if end_date.present?
|
639
|
+
end_date_tt = Time.parse(end_date)
|
640
|
+
if end_date < time_now
|
641
|
+
used_end_date = end_date_tt
|
642
|
+
# Rails.logger.debug("end_date: используем аргумент: #{end_date_tt}")
|
643
|
+
else
|
644
|
+
used_end_date = time_now
|
645
|
+
# Rails.logger.debug("end_date: используем текущее время")
|
646
|
+
end
|
647
|
+
else
|
648
|
+
used_end_date = time_now
|
649
|
+
# Rails.logger.debug("end_date: используем текущее время")
|
650
|
+
end
|
651
|
+
used_end_date_str = used_end_date.strftime('%Y/%m/%d')
|
652
|
+
|
653
|
+
{
|
654
|
+
used_start_date: used_start_date,
|
655
|
+
used_start_date_str: used_start_date_str,
|
656
|
+
used_end_date: used_end_date,
|
657
|
+
used_end_date_str: used_end_date_str
|
658
|
+
}
|
659
|
+
|
660
|
+
end
|
661
|
+
|
662
|
+
def self._calc_free_busy_areas(pstats)
|
663
|
+
sum_free_areas = 0
|
664
|
+
sum_busy_areas = 0
|
665
|
+
all_props = Property.all
|
666
|
+
all_props.each do |prop|
|
667
|
+
ppstats = pstats.where(:property_id => prop.id).ordered_by_created_at.last
|
668
|
+
sum_free_areas += ppstats.free_areas
|
669
|
+
sum_busy_areas += ppstats.busy_areas
|
670
|
+
end
|
671
|
+
{
|
672
|
+
sum_free_areas:sum_free_areas,
|
673
|
+
sum_busy_areas:sum_busy_areas
|
674
|
+
}
|
286
675
|
end
|
287
676
|
|
288
677
|
end
|