@@ -47,39 +47,17 @@ defmodule Transport.StatsHandlerTest do
47
47
end
48
48
49
49
test "climate_resilience_bill_count" do
50
- aom = insert ( :aom , population: 1_000 )
51
- insert ( :dataset , aom: aom , is_active: false , custom_tags: [ "loi-climat-resilience" ] , type: "public-transit" )
52
- insert ( :dataset , aom: aom , is_active: true , custom_tags: [ "loi-climat-resilience" ] , type: "public-transit" )
53
- insert ( :dataset , aom: aom , is_active: true , custom_tags: [ "loi-climat-resilience" ] , type: "public-transit" )
54
-
55
- insert ( :dataset ,
56
- aom: aom ,
57
- is_active: true ,
58
- custom_tags: [ "loi-climat-resilience" , "foo" ] ,
59
- type: "low-emission-zones"
60
- )
50
+ insert ( :dataset , is_active: false , custom_tags: [ "loi-climat-resilience" ] , type: "public-transit" )
51
+ insert ( :dataset , is_active: true , custom_tags: [ "loi-climat-resilience" ] , type: "public-transit" )
52
+ insert ( :dataset , is_active: true , custom_tags: [ "loi-climat-resilience" ] , type: "public-transit" )
53
+ insert ( :dataset , is_active: true , custom_tags: [ "loi-climat-resilience" , "foo" ] , type: "low-emission-zones" )
61
54
62
55
assert % {
63
56
climate_resilience_bill_count: % {
64
57
"low-emission-zones" => 1 ,
65
58
"public-transit" => 2
66
59
}
67
60
} = compute_stats ( )
68
-
69
- # Stored as expected in the database
70
- store_stats ( )
71
-
72
- decimal_1 = Decimal . new ( 1 )
73
- decimal_2 = Decimal . new ( 2 )
74
-
75
- assert [
76
- % DB.StatsHistory { metric: "climate_resilience_bill_count::low-emission-zones" , value: ^ decimal_1 } ,
77
- % DB.StatsHistory { metric: "climate_resilience_bill_count::public-transit" , value: ^ decimal_2 }
78
- ] =
79
- DB.StatsHistory
80
- |> where ( [ s ] , like ( s . metric , "climate_resilience_bill_count%" ) )
81
- |> order_by ( [ s ] , s . metric )
82
- |> DB.Repo . all ( )
83
61
end
84
62
85
63
test "store_stats" do
@@ -98,6 +76,16 @@ defmodule Transport.StatsHandlerTest do
98
76
resource_id: insert ( :resource , format: "gbfs" ) . id
99
77
)
100
78
79
+ # climate_resilience_bill data
80
+ insert ( :dataset , is_active: false , custom_tags: [ "loi-climat-resilience" ] , type: "public-transit" )
81
+ insert ( :dataset , is_active: true , custom_tags: [ "loi-climat-resilience" ] , type: "public-transit" )
82
+ insert ( :dataset , is_active: true , custom_tags: [ "loi-climat-resilience" ] , type: "public-transit" )
83
+ insert ( :dataset , is_active: true , custom_tags: [ "loi-climat-resilience" , "foo" ] , type: "low-emission-zones" )
84
+
85
+ # reuses stats
86
+ insert ( :reuse , type: "api" , metric_discussions: 0 , metric_followers: 2 , metric_views: 5 )
87
+ insert ( :reuse , type: "visualization" , metric_discussions: 1 , metric_followers: 1 , metric_views: 10 )
88
+
101
89
stats = compute_stats ( )
102
90
store_stats ( )
103
91
assert DB.Repo . aggregate ( DB.StatsHistory , :count , :id ) >= Enum . count ( stats )
@@ -109,18 +97,33 @@ defmodule Transport.StatsHandlerTest do
109
97
|> Map . keys ( )
110
98
|> Enum . map ( & to_string / 1 )
111
99
|> Enum . reject (
112
- & String . starts_with? ( & 1 , [ "gtfs_rt_types" , "climate_resilience_bill_count" , "count_geo_data_lines" ] )
100
+ & String . starts_with? ( & 1 , [ "gtfs_rt_types" , "climate_resilience_bill_count" , "count_geo_data_lines" , "reuses" ] )
113
101
)
114
102
115
103
assert MapSet . subset? ( MapSet . new ( stats_metrics ) , MapSet . new ( all_metrics ) )
116
104
assert Enum . member? ( all_metrics , "gtfs_rt_types::vehicle_positions" )
117
105
assert Enum . member? ( all_metrics , "gtfs_rt_types::trip_updates" )
118
106
assert Enum . member? ( all_metrics , "count_geo_data_lines::irve" )
107
+ assert Enum . member? ( all_metrics , "reuses::nb_reuses" )
119
108
120
- expected = Decimal . new ( "2" )
109
+ expected = Decimal . new ( 2 )
121
110
assert % { value: ^ expected } = DB.Repo . get_by! ( DB.StatsHistory , metric: "gtfs_rt_types::vehicle_positions" )
122
- expected = Decimal . new ( "1" )
111
+ expected = Decimal . new ( 1 )
123
112
assert % { value: ^ expected } = DB.Repo . get_by! ( DB.StatsHistory , metric: "gbfs_v3.0_count" )
113
+ expected = Decimal . new ( 15 )
114
+ assert % { value: ^ expected } = DB.Repo . get_by! ( DB.StatsHistory , metric: "reuses::sum_metric_views" )
115
+
116
+ decimal_1 = Decimal . new ( 1 )
117
+ decimal_2 = Decimal . new ( 2 )
118
+
119
+ assert [
120
+ % DB.StatsHistory { metric: "climate_resilience_bill_count::low-emission-zones" , value: ^ decimal_1 } ,
121
+ % DB.StatsHistory { metric: "climate_resilience_bill_count::public-transit" , value: ^ decimal_2 }
122
+ ] =
123
+ DB.StatsHistory
124
+ |> where ( [ s ] , like ( s . metric , "climate_resilience_bill_count%" ) )
125
+ |> order_by ( [ s ] , s . metric )
126
+ |> DB.Repo . all ( )
124
127
end
125
128
126
129
test "count dataset per format" do
@@ -251,4 +254,20 @@ defmodule Transport.StatsHandlerTest do
251
254
} == gbfs_stats ( )
252
255
end
253
256
end
257
+
258
+ test "reuses_stats" do
259
+ insert ( :reuse , type: "api" , metric_discussions: 0 , metric_followers: 2 , metric_views: 5 )
260
+ insert ( :reuse , type: "visualization" , metric_discussions: 1 , metric_followers: 1 , metric_views: 10 )
261
+
262
+ assert % {
263
+ :nb_reuses => 2 ,
264
+ :sum_metric_discussions => 1 ,
265
+ :sum_metric_followers => 3 ,
266
+ :sum_metric_views => 15 ,
267
+ "api" => 1 ,
268
+ "visualization" => 1
269
+ } = reuses_stats = reuses_stats ( )
270
+
271
+ assert % { reuses: ^ reuses_stats } = compute_stats ( )
272
+ end
254
273
end
0 commit comments