Zirok05 commited on
Commit
3958ee3
·
verified ·
1 Parent(s): a69fc0b

Update app/simulation/core/traffic_generator.py

Browse files
app/simulation/core/traffic_generator.py CHANGED
@@ -8,13 +8,12 @@ class TrafficGenerator:
8
  self.total = total_applications
9
  np.random.seed(random_seed)
10
 
11
- # Параметры интенсивности с провалом после обеда
12
  self.intensity_params = {
13
  'background': 0.1,
14
  'day_center': 13, 'day_amplitude': 0.9, 'day_width': 2.5, # день поуже
15
  'evening_center': 19.5, 'evening_amplitude': 1.3, 'evening_width': 2.2, # вечер пораньше и пошире
16
- 'afternoon_dip_center': 15.5, 'afternoon_dip_strength': 0.3, 'afternoon_dip_width': 1.5,
17
- # провал после обеда
18
  'noise_level': 0.1
19
  }
20
 
@@ -24,7 +23,7 @@ class TrafficGenerator:
24
 
25
  def loan_intensity_periodic(self, t, impulses=None):
26
  """
27
- Функция интенсивности с провалом после обеда
28
 
29
  t: время в часах (может быть дробным)
30
  impulses: список словарей вида
@@ -173,7 +172,7 @@ class TrafficGenerator:
173
  plt.axhline(y=mean_val, color='red', linestyle='--',
174
  alpha=0.7, linewidth=2, label=f'Среднее: {mean_val:.0f}')
175
 
176
- # Отметим импульсы на графике
177
  if impulses:
178
  for imp in impulses:
179
  imp_hours = self._time_to_hours(imp['time']) % 24
@@ -183,7 +182,6 @@ class TrafficGenerator:
183
  plt.plot(idx, counts_sorted[idx], 'g*', markersize=15,
184
  label=f'Импульс {imp["strength"]:.1f}x' if idx == 0 else '')
185
 
186
- # Отметим провал после обеда
187
  dip_idx = [i for i, h in enumerate(hours_sorted) if 14 <= h <= 16]
188
  if dip_idx:
189
  plt.axvspan(dip_idx[0] - 0.4, dip_idx[-1] + 0.4, alpha=0.2, color='gray',
@@ -208,8 +206,6 @@ class TrafficGenerator:
208
 
209
  return hours_sorted, counts_sorted
210
 
211
-
212
- # Пример использования
213
  # if __name__ == "__main__":
214
  # # Создаём генератор
215
  # gen = TrafficGenerator(total_applications=110000)
@@ -225,7 +221,7 @@ class TrafficGenerator:
225
  # print("\nС импульсом в 5:30:")
226
  # counts = gen.generate_minute_counts(start_hour=17, impulses=impulses)
227
  #
228
- # # 3. Построить график
229
  # gen.plot_distribution(start_hour=17, impulses=impulses)
230
  #
231
  # # 4. Случайные импульсы
 
8
  self.total = total_applications
9
  np.random.seed(random_seed)
10
 
11
+ # Параметры интенсивности
12
  self.intensity_params = {
13
  'background': 0.1,
14
  'day_center': 13, 'day_amplitude': 0.9, 'day_width': 2.5, # день поуже
15
  'evening_center': 19.5, 'evening_amplitude': 1.3, 'evening_width': 2.2, # вечер пораньше и пошире
16
+ 'afternoon_dip_center': 15.5, 'afternoon_dip_strength': 0.3, 'afternoon_dip_width': 1.5, # провал после обеда
 
17
  'noise_level': 0.1
18
  }
19
 
 
23
 
24
  def loan_intensity_periodic(self, t, impulses=None):
25
  """
26
+ Функция интенсивности
27
 
28
  t: время в часах (может быть дробным)
29
  impulses: список словарей вида
 
172
  plt.axhline(y=mean_val, color='red', linestyle='--',
173
  alpha=0.7, linewidth=2, label=f'Среднее: {mean_val:.0f}')
174
 
175
+ # Импульсы на графике
176
  if impulses:
177
  for imp in impulses:
178
  imp_hours = self._time_to_hours(imp['time']) % 24
 
182
  plt.plot(idx, counts_sorted[idx], 'g*', markersize=15,
183
  label=f'Импульс {imp["strength"]:.1f}x' if idx == 0 else '')
184
 
 
185
  dip_idx = [i for i, h in enumerate(hours_sorted) if 14 <= h <= 16]
186
  if dip_idx:
187
  plt.axvspan(dip_idx[0] - 0.4, dip_idx[-1] + 0.4, alpha=0.2, color='gray',
 
206
 
207
  return hours_sorted, counts_sorted
208
 
 
 
209
  # if __name__ == "__main__":
210
  # # Создаём генератор
211
  # gen = TrafficGenerator(total_applications=110000)
 
221
  # print("\nС импульсом в 5:30:")
222
  # counts = gen.generate_minute_counts(start_hour=17, impulses=impulses)
223
  #
224
+ # # 3. График
225
  # gen.plot_distribution(start_hour=17, impulses=impulses)
226
  #
227
  # # 4. Случайные импульсы