Skip to content

feat(place): event scrape#118

Open
pkheav wants to merge 565 commits into
masterfrom
GuestScrape
Open

feat(place): event scrape#118
pkheav wants to merge 565 commits into
masterfrom
GuestScrape

Conversation

@pkheav
Copy link
Copy Markdown
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.

stakach and others added 30 commits October 6, 2020 09:56
easier to track when debugging and configuring
Co-authored-by: Philip Kheav <philip.kheav@hotmail.com>
* feat(place area count): initial work

* feat(place area count): point check working

* feat: current progress on area counting

* initial work on S2 cells

* feat(area management): complete area management

grabs location data
count how many devices in an area
provide a summary of the building
to `device_locations` function
* feat(samsung): initial commit

* fix(samsung): cleanup formatting and move to displays folder

* feat(samsung): port over more methods

* fix(samsung): update to pass driver test runner

* feat(samsung): port over power function

* feat(samsung): port over volume methods

* fix(samsung): force compiler to process type for previous_volume as Int32

* feat(samsung): port over more methods

* feat(samsung): port over more methods

* fix(samsung): use enum to store constant values for commands

* fix(samsung): cleanup types

* chore(samsung): cleanup todos

* fix(samsung): initialise @blank as nil

* fix(samsung): add spec tests

* fix(samsung): use safe getter to get self values

* fix(samsung): use type safe getters when trying to access self values everywhere

* fix(samsung): fix all warnings when running with spec

* fix(samsung): commit correct file

* fix(samsung): add check for sending of data from connected method in spec

* fix(samsung): fix abstract tokenizer and add responses in spec

* feat(samsung): add skeleton and checksum verification for received method

* feat(samsung): complete most of the received method

* fix(samsung): use task signals

* feat(samsung): port over split function

* feat(samsung): add status value checks to spec

* fix(samsung): save screen_split value

* feat(samsung): add macro to define methods

* refactor(samsung): use Crystal's Bytes

* chore(samsung): cleanup do_send param types

* chore(samsung): remove documentation links

* refactor(samsung): rename to MDCProtocol

* refactor(samsung): use Enum's from_value instead of new

* refactor(samsung): use question methods for Enums

* refactor(samsung): update do_send to only take in COMMAND enums

* refactor(samsung): use less intermediate arrays in do_send

* chore(samsung): fix indentation

* chore(samsung): remove custom command method

* refactor/fix(samsung): move command assembly into enum class and use correct method to calculate checksum

* refactor(samsung): more Bytes

* chore(samsung): remove set timer method

* chore(samsung): use camelcase convention for type names

* chore(samsung) remove wake method

* chore(samsung): remove ScaleModes enum and split method

* fix(samsung): use panel mute command for mute

* fix(mdc_protocol): use Powerable interface

* fix(mdc_protocol): use Muteable interface

* fix(mdc_protocol): implement Switchable interface

* fix(mdc_protocol): initiliase previous volume

* fix(mdc_protocol): use setting? instead of setting

* feat(samsung): add Security annotation to methods

* refactor(mdc_protocol): remove init_tokenizer method

* refactor(mdc_protocol): use instance variables

* fix(mdc_protocol): use immediate flag for scheduler

* fix(mdc_protocol): let compiler infer type

* fix(mdc_protocol): let compiler infer broadcast type

* fix(mdc_protocol): define array for method names inline with macro

* feat(mdc_protocol): add logic for message indicator

* chore(mdc): remove completed todo

* fix(mdc): define indicator as constant

* fix(mdc): use indicator constant when building command

Co-authored-by: Caspian Baska <caspianbaska@gmail.com>

* chore(mdc): clean up do_device_config

* fix(mdc): stringify setting names

* fix(mdc): update require lines

* fix(mdc): group device settings

* chore(mdc): fix indentation

* fix(mdc): return power after power query

* chore(mdc): remove broadcast

* fix(mdc): remove old ruby code

* fix(mdc): set input target as nil initially

* fix(mdc): set power properly

* fix(mdc): create variable for hard_off

* fix(mdc): assign variables when checking self values

* fix(mdc): assign more self values to variables

* chore(mdc): remove some logging

* fix(mdc): use Muteable interface properly

* fix(mdc): add spec for changing volume

* fix(mdc): use correct hex value for spec

* fix(mdc): use shorter way of checking self values

* fix(mdc): use as_bool instead of as_bool?

* fix(mdc): use strict parse instead of parse?

Co-authored-by: Kim Burgess <kim@place.technology>

* fix(mdc): correctly use commit github suggestion

* fix(mdc): use if statement for checking MuteLayer

* chore(mdc): use CamelCase

* fix(samsung): address feedback

* chore(mdc): use Input instead of Inputs

* chore(mdc): use state instead of power

* fix(mdc): change power_target to instance variable

* fix(mdc): use shorter method to check MuteLayer

* fix(mdc): remove unmute audio

* fix(mdc): set input_target correctly

* fix(mdc): don't use linebreak in error logging

* fix(mdc): make check_power_state method private

* fix(mdc): don't map response

* fix(mdc): set type to UInt8 to reduce casting

* feat(mdc): add specs for switch_to and power

Co-authored-by: Philip Kheav <pkheav@Philips-MacBook-Pro.local>
Co-authored-by: Caspian Baska <caspianbaska@gmail.com>
Co-authored-by: Kim Burgess <kim@place.technology>
* feat(desk bookings): add desk bookings locations

implementing location services so bookings can be highlighted on the map

* feat(desk bookings): add spec
* fix(place/area/config): allow zone.metadata.area.properties.Hash

support

"areas": [
        {
            ...
            "properties": {
                "label_location": {
                    "x": 0.5089,
                    "y": 0.6673
                }
            }

* this should fix it

Co-authored-by: Stephen von Takach <steve@place.tech>
@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

9 participants