Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweak: Train Crowding Widget Logging #1839

Merged
merged 18 commits into from
Sep 8, 2023
Merged

Conversation

cmaddox5
Copy link
Contributor

Asana task: Add logging to triptych app - pt 1

Added a log for each car so we can make some Splunk charts. The biggest change is a new config for the Carriage objects in the API. I wanted to make sure we tracked the car_number for the logs. Once merged, I will work on some Splunk charts/tables.

  • Tests added?

@cmaddox5 cmaddox5 requested review from a team and hannahpurcell and removed request for a team August 29, 2023 13:52
@github-actions
Copy link

Coverage of commit 09d5f13

Summary coverage rate:
  lines......: 41.3% (2281 of 5526 lines)
  functions..: 42.7% (1042 of 2443 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/widgets/train_crowding.ex             |83.3%     30|55.6%     9|    -      0
  lib/screens/v2/widget_instance/train_crowding.ex                         |66.7%     33|93.3%    15|    -      0
  lib/screens/vehicles/carriage.ex                                         | 100%      1| 100%     2|    -      0
  lib/screens/vehicles/parser.ex                                           | 0.0%     21| 0.0%     8|    -      0
  lib/screens/vehicles/vehicle.ex                                          |25.0%      4|66.7%     3|    -      0

Download coverage report

Comment on lines 100 to 109
defp log_crowding_info(prediction, crowding_config) do
Enum.each(
prediction.vehicle.carriages,
fn %Screens.Vehicles.Carriage{} = carriage ->
Logger.info(
"[train_crowding car_crowding_info] station_id=#{crowding_config.station_id} direction_id=#{crowding_config.direction_id} car_number=#{carriage.car_number} vehicle_id=#{prediction.vehicle.id} crowding_level=#{carriage.occupancy_status} trip_id=#{prediction.trip.id} prediction_id=#{prediction.id}"
)
end
)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of separate logging for each car, can we log the array of all car crowding for a vehicle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason for splitting out the cars is for easier grouping and comparisons in Splunk tables/dashboards. I worry that keeping all info in the same log will require some complicated log parsing. I guess we could go with one log and, as long as we ensure sorting is consistent, look for any time that the serialized arrays are not equal. Is that what you had in mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's what I had in mind. What is the use case for grouping and comparisons on the car level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we wanting to track changes in crowding at the car level? That's was my motivation going into this task. We are wanting to see how often crowding changes for each trip. Regardless, I think that you're idea should accomplish the same thing with far fewer logs, so I'm gonna try that out.

@cmaddox5 cmaddox5 assigned hannahpurcell and unassigned cmaddox5 Sep 1, 2023
@github-actions
Copy link

github-actions bot commented Sep 5, 2023

Coverage of commit 9f2a37e

Summary coverage rate:
  lines......: 40.7% (2291 of 5625 lines)
  functions..: 42.2% (1050 of 2490 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/bus_eink.ex                           |66.7%     24|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/bus_shelter.ex                        |69.2%     26|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/dup.ex                                |65.0%     20|33.3%     9|    -      0
  lib/screens/v2/candidate_generator/gl_eink.ex                            |17.4%     46|16.7%    18|    -      0
  lib/screens/v2/candidate_generator/pre_fare.ex                           |44.4%     45|33.3%    18|    -      0
  lib/screens/v2/candidate_generator/solari.ex                             |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/solari_large.ex                       |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/triptych.ex                           |10.0%     10|16.7%     6|    -      0
  lib/screens/v2/candidate_generator/widgets/train_crowding.ex             |66.7%     36|55.6%     9|    -      0
  lib/screens/v2/screen_data.ex                                            |62.1%    132|53.3%    30|    -      0
  lib/screens/v2/widget_instance/train_crowding.ex                         |66.7%     33|93.3%    15|    -      0
  lib/screens/vehicles/carriage.ex                                         | 100%      1| 100%     2|    -      0
  lib/screens/vehicles/parser.ex                                           | 0.0%     21| 0.0%     8|    -      0
  lib/screens/vehicles/vehicle.ex                                          |25.0%      4|66.7%     3|    -      0
  lib/screens_web/controllers/v2/screen_api_controller.ex                  | 0.0%     42| 0.0%    14|    -      0

Download coverage report

@cmaddox5 cmaddox5 temporarily deployed to dev-green September 6, 2023 13:44 — with GitHub Actions Inactive
@cmaddox5 cmaddox5 temporarily deployed to dev-green September 6, 2023 14:14 — with GitHub Actions Inactive
@github-actions
Copy link

github-actions bot commented Sep 6, 2023

Coverage of commit 6f8b9f1

Summary coverage rate:
  lines......: 40.7% (2291 of 5625 lines)
  functions..: 42.2% (1050 of 2490 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/bus_eink.ex                           |66.7%     24|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/bus_shelter.ex                        |69.2%     26|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/dup.ex                                |65.0%     20|33.3%     9|    -      0
  lib/screens/v2/candidate_generator/gl_eink.ex                            |17.4%     46|16.7%    18|    -      0
  lib/screens/v2/candidate_generator/pre_fare.ex                           |44.4%     45|33.3%    18|    -      0
  lib/screens/v2/candidate_generator/solari.ex                             |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/solari_large.ex                       |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/triptych.ex                           |10.0%     10|16.7%     6|    -      0
  lib/screens/v2/candidate_generator/widgets/train_crowding.ex             |66.7%     36|55.6%     9|    -      0
  lib/screens/v2/screen_data.ex                                            |62.1%    132|53.3%    30|    -      0
  lib/screens/v2/widget_instance/train_crowding.ex                         |66.7%     33|93.3%    15|    -      0
  lib/screens/vehicles/carriage.ex                                         | 100%      1| 100%     2|    -      0
  lib/screens/vehicles/parser.ex                                           | 0.0%     21| 0.0%     8|    -      0
  lib/screens/vehicles/vehicle.ex                                          |25.0%      4|66.7%     3|    -      0
  lib/screens_web/controllers/v2/screen_api_controller.ex                  | 0.0%     42| 0.0%    14|    -      0

Download coverage report

@cmaddox5 cmaddox5 temporarily deployed to dev-green September 6, 2023 14:32 — with GitHub Actions Inactive
@github-actions
Copy link

github-actions bot commented Sep 6, 2023

Coverage of commit 0f3ac3c

Summary coverage rate:
  lines......: 40.7% (2291 of 5625 lines)
  functions..: 42.2% (1050 of 2490 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/bus_eink.ex                           |66.7%     24|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/bus_shelter.ex                        |69.2%     26|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/dup.ex                                |65.0%     20|33.3%     9|    -      0
  lib/screens/v2/candidate_generator/gl_eink.ex                            |17.4%     46|16.7%    18|    -      0
  lib/screens/v2/candidate_generator/pre_fare.ex                           |44.4%     45|33.3%    18|    -      0
  lib/screens/v2/candidate_generator/solari.ex                             |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/solari_large.ex                       |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/triptych.ex                           |10.0%     10|16.7%     6|    -      0
  lib/screens/v2/candidate_generator/widgets/train_crowding.ex             |66.7%     36|55.6%     9|    -      0
  lib/screens/v2/screen_data.ex                                            |62.1%    132|53.3%    30|    -      0
  lib/screens/v2/widget_instance/train_crowding.ex                         |66.7%     33|93.3%    15|    -      0
  lib/screens/vehicles/carriage.ex                                         | 100%      1| 100%     2|    -      0
  lib/screens/vehicles/parser.ex                                           | 0.0%     21| 0.0%     8|    -      0
  lib/screens/vehicles/vehicle.ex                                          |25.0%      4|66.7%     3|    -      0
  lib/screens_web/controllers/v2/screen_api_controller.ex                  | 0.0%     42| 0.0%    14|    -      0

Download coverage report

@cmaddox5 cmaddox5 temporarily deployed to dev-green September 6, 2023 15:46 — with GitHub Actions Inactive
@github-actions
Copy link

github-actions bot commented Sep 6, 2023

Coverage of commit 1ffe934

Summary coverage rate:
  lines......: 40.7% (2291 of 5625 lines)
  functions..: 42.2% (1050 of 2490 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/bus_eink.ex                           |66.7%     24|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/bus_shelter.ex                        |69.2%     26|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/dup.ex                                |65.0%     20|33.3%     9|    -      0
  lib/screens/v2/candidate_generator/gl_eink.ex                            |17.4%     46|16.7%    18|    -      0
  lib/screens/v2/candidate_generator/pre_fare.ex                           |44.4%     45|33.3%    18|    -      0
  lib/screens/v2/candidate_generator/solari.ex                             |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/solari_large.ex                       |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/triptych.ex                           |10.0%     10|16.7%     6|    -      0
  lib/screens/v2/candidate_generator/widgets/train_crowding.ex             |66.7%     36|55.6%     9|    -      0
  lib/screens/v2/screen_data.ex                                            |62.1%    132|53.3%    30|    -      0
  lib/screens/v2/widget_instance/train_crowding.ex                         |66.7%     33|93.3%    15|    -      0
  lib/screens/vehicles/carriage.ex                                         | 100%      1| 100%     2|    -      0
  lib/screens/vehicles/parser.ex                                           | 0.0%     21| 0.0%     8|    -      0
  lib/screens/vehicles/vehicle.ex                                          |25.0%      4|66.7%     3|    -      0
  lib/screens_web/controllers/v2/screen_api_controller.ex                  | 0.0%     42| 0.0%    14|    -      0

Download coverage report

Comment on lines 85 to 88
ScreenData.by_screen_id(screen_id,
is_real_screen: is_screen,
screen_id: screen_id,
triptych_pane: triptych_pane
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I was worried that we're passing the triptych_pane for all screen cases, including non-triptychs. I think that means by the time fetch_data is run in ScreenData, all screens except triptych will have the option triptych_pane: nil. Fortunately, right now, the only candidate_generator that pays attention to opts is the triptych one. (But let's say one day we want to use this opts in the candidate_generator for another screen type, that screen will suddenly have this triptych_pane option out of the blue.) I'm thinking it might be better if this option is passed conditionally? I dunno, does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one of the advantages to using an opts list is that they can be arbitrary in length and a function doing a lookup in opts only needs to look for what they know they need. Similar to params in this action. This action is used by all screen types but references very specific values only needed by certain screen types. Because a lookup of key that doesn't exist is safe for these lists, we just need to do some nil checks before using them.

I definitely see where you are coming from though. My biggest hesitation with conditionally adding it is that it will make the code here a little more complex for no drastic benefit. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I can see that. Works for me!

@github-actions
Copy link

github-actions bot commented Sep 6, 2023

Coverage of commit 4861948

Summary coverage rate:
  lines......: 40.8% (2291 of 5622 lines)
  functions..: 42.2% (1050 of 2490 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/bus_eink.ex                           |66.7%     24|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/bus_shelter.ex                        |69.2%     26|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/dup.ex                                |65.0%     20|33.3%     9|    -      0
  lib/screens/v2/candidate_generator/gl_eink.ex                            |17.4%     46|16.7%    18|    -      0
  lib/screens/v2/candidate_generator/pre_fare.ex                           |44.4%     45|33.3%    18|    -      0
  lib/screens/v2/candidate_generator/solari.ex                             |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/solari_large.ex                       |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/triptych.ex                           |10.0%     10|16.7%     6|    -      0
  lib/screens/v2/candidate_generator/widgets/train_crowding.ex             |72.7%     33|55.6%     9|    -      0
  lib/screens/v2/screen_data.ex                                            |62.1%    132|53.3%    30|    -      0
  lib/screens/v2/widget_instance/train_crowding.ex                         |66.7%     33|93.3%    15|    -      0
  lib/screens/vehicles/carriage.ex                                         | 100%      1| 100%     2|    -      0
  lib/screens/vehicles/parser.ex                                           | 0.0%     21| 0.0%     8|    -      0
  lib/screens/vehicles/vehicle.ex                                          |25.0%      4|66.7%     3|    -      0
  lib/screens_web/controllers/v2/screen_api_controller.ex                  | 0.0%     42| 0.0%    14|    -      0

Download coverage report

@cmaddox5 cmaddox5 assigned hannahpurcell and unassigned cmaddox5 Sep 7, 2023
@cmaddox5 cmaddox5 assigned hannahpurcell and unassigned cmaddox5 Sep 8, 2023
evergreen_content_instances_fn \\ &Widgets.Evergreen.evergreen_content_instances/1,
local_evergreen_set_instances_fn \\ &Widgets.LocalEvergreenSet.local_evergreen_set_instances/1
) do
[
fn -> crowding_widget_instances_fn.(config) end,
fn -> crowding_widget_instances_fn.(config, opts) end,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From our huddle conversation, I suggested this so the train_crowding widget only has the stuff it needs

Suggested change
fn -> crowding_widget_instances_fn.(config, opts) end,
fn -> crowding_widget_instances_fn.(config, opts[:logging_options]) end,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then the associated changes are needed in the train_crowding candidate_generator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see. I misunderstood. Will make that change now.

@cmaddox5 cmaddox5 assigned hannahpurcell and unassigned cmaddox5 Sep 8, 2023
@github-actions
Copy link

github-actions bot commented Sep 8, 2023

Coverage of commit d596f36

Summary coverage rate:
  lines......: 40.8% (2291 of 5622 lines)
  functions..: 42.2% (1050 of 2490 functions)
  branches...: no data found

Files changed coverage rate:
                                                                           |Lines       |Functions  |Branches    
  Filename                                                                 |Rate     Num|Rate    Num|Rate     Num
  ===============================================================================================================
  lib/screens/v2/candidate_generator/bus_eink.ex                           |66.7%     24|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/bus_shelter.ex                        |69.2%     26|41.7%    12|    -      0
  lib/screens/v2/candidate_generator/dup.ex                                |65.0%     20|33.3%     9|    -      0
  lib/screens/v2/candidate_generator/gl_eink.ex                            |17.4%     46|16.7%    18|    -      0
  lib/screens/v2/candidate_generator/pre_fare.ex                           |44.4%     45|33.3%    18|    -      0
  lib/screens/v2/candidate_generator/solari.ex                             |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/solari_large.ex                       |72.7%     11|57.1%     7|    -      0
  lib/screens/v2/candidate_generator/triptych.ex                           |10.0%     10|16.7%     6|    -      0
  lib/screens/v2/candidate_generator/widgets/train_crowding.ex             |72.7%     33|55.6%     9|    -      0
  lib/screens/v2/screen_data.ex                                            |62.1%    132|53.3%    30|    -      0
  lib/screens/v2/widget_instance/train_crowding.ex                         |66.7%     33|93.3%    15|    -      0
  lib/screens/vehicles/carriage.ex                                         | 100%      1| 100%     2|    -      0
  lib/screens/vehicles/parser.ex                                           | 0.0%     21| 0.0%     8|    -      0
  lib/screens/vehicles/vehicle.ex                                          |25.0%      4|66.7%     3|    -      0
  lib/screens_web/controllers/v2/screen_api_controller.ex                  | 0.0%     42| 0.0%    14|    -      0

Download coverage report

Copy link
Contributor

@hannahpurcell hannahpurcell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@cmaddox5 cmaddox5 merged commit 7fae92a into master Sep 8, 2023
2 checks passed
@cmaddox5 cmaddox5 deleted the cm/ol-crowding-logging branch September 8, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants