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

feat(place): event scrape #118

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

feat(place): event scrape #118

wants to merge 26 commits into from

Conversation

pkheav
Copy link
Contributor

@pkheav pkheav commented Mar 15, 2021

Looks good to me testing on my local partner environment. Let me know if anything else should be changed or added @w-le @stakach

image

Also @stakach , might need your help figuring out why these methods

# TODO: figure out why these 2 methods don't work
# def module(module_id : String)
# placeos_client.modules.fetch module_id
# end
# def modules(q : String? = nil,
# limit : Int32 = 20,
# offset : Int32 = 0,
# control_system_id : String? = nil,
# driver_id : String? = nil)
# placeos_client.modules.search(
# q: q,
# limit: limit,
# offset: offset,
# control_system_id: control_system_id,
# driver_id: driver_id
# )
# end
don't work as they would be cleaner and probably be a useful addition to staff_api.cr as they're more general than the working methods I added instead
def module(module_id : String)
response = get("/api/engine/v2/modules/#{module_id}", headers: {
"Accept" => "application/json",
"Authorization" => "Bearer #{token}",
})
raise "unexpected response for module id #{module_id}: #{response.status_code}\n#{response.body}" unless response.success?
begin
JSON.parse(response.body)
rescue error
logger.debug { "issue parsing module #{module_id}:\n#{response.body.inspect}" }
raise error
end
end
def modules_from_system(system_id : String)
response = get("/api/engine/v2/modules?control_system_id=#{system_id}", headers: {
"Accept" => "application/json",
"Authorization" => "Bearer #{token}",
})
raise "unexpected response for modules for #{system_id}: #{response.status_code}\n#{response.body}" unless response.success?
begin
JSON.parse(response.body)
rescue error
logger.debug { "issue getting modules for #{system_id}:\n#{response.body.inspect}" }
raise error
end
end
.

Oh yeah, tried writing a spec but couldn't get it working as it seems like the spec runner is a little bit flaky.

@pkheav pkheav requested review from stakach and w-le March 15, 2021 17:45
@pkheav pkheav changed the title Guest scrape Event scrape Mar 15, 2021
@caspiano caspiano requested review from kimburgess and w-le and removed request for w-le June 10, 2021 11:46
systems: {} of String => SystemWithEvents
}

now = Time.local
Copy link
Contributor

Choose a reason for hiding this comment

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

It's unlikely the the server TZ will be the same as the users TZ.

May be worth pulling a larger time slice, then filtering on front-ends, or support passing a timezone either to this method call, or applying as a setting for the driver instance.

end_epoch = now.at_end_of_day.to_unix

@zone_ids.each do |z_id|
staff_api.systems(zone_id: z_id).get.as_a.each do |sys|
Copy link
Contributor

Choose a reason for hiding this comment

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

The #get here will block while each request completes, forcing them to run sequentially. It looks like these could happen safely concurrently.

It should be possible to reorganise this so that you map @zone_ids to an array of Futures (the staff_api.systems(..) call, then combine these into your response.


response[:systems][sys_id] = SystemWithEvents.new(
name: sys["name"].as_s,
zones: Array(String).from_json(sys["zones"].to_json),
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a roundtrip through some JSON serialisation here that doesn't look to be required.

Comment on lines +63 to +65
booking_module = staff_api.modules_from_system(sys_id).get.as_a.find { |mod| mod["name"] == "Bookings" }
# If the system has a booking module with bookings
if booking_module && (bookings = staff_api.get_module_state(booking_module["id"].as_s).get["bookings"]?)
Copy link
Contributor

Choose a reason for hiding this comment

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

You may need to expand the staff API driver to support this, but this can collapse into a single query via this endpoint:

https://github.com/PlaceOS/rest-api/blob/5d3acc0cff8d949d360a8f6de9c2e916c52f5cf1/src/placeos-rest-api/controllers/systems.cr#L314-L321

@caspiano caspiano changed the title Event scrape feat(place): event scrape May 31, 2022
@w-le w-le assigned w-le and unassigned pkheav Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants