How to use session_end method in Slash

Best Python code snippet using slash

02_stationary_view_v1.py

Source:02_stationary_view_v1.py Github

copy

Full Screen

1#!/bin/python2#3# STATIONARY SESSIONS VIEW V14# ===========================5#6# This executable computes a materialized view of the facts table with only7# stationary sessions.8#9# Stationary sessions are those sessions that: (i) lasted for at least 10 minutes;10# (ii) were completed by a userid-mac pair which was classified as main (or11# primary)12#13# We merge adjacent sessions that take place in the same AP within 10 minutes14# of each other. Sessions that take place in the same AP within 10 minutes of15# each other but are interspersed by sessions taking places in other APs are16# not merged, since they are not by definition adjacent.17#18# There is a considerable amount of overlapping sessions in the facts table19# (over 20 percent). To disentangle those sessions we bring the session end20# time of an overlapping session back to 1 second before the start of the next21# session. If sessions start at the same time we arbitrarily delete one of them.22import logging23import argparse24from sqlalchemy import create_engine25from __init__ import resolve_args26def create_view(engine):27 with engine.begin() as conn:28 conn.execute(29 f"""30 CREATE MATERIALIZED VIEW IF NOT EXISTS views.stationary_session AS31 WITH f AS (32 SELECT 33 f.userid_key,34 f.ap_key,35 f.status,36 f.session_start,37 f.session_end,38 f.session_end - f.session_start AS session_duration,39 f.rssi40 FROM (41 SELECT42 f.userid_key,43 f.ap_key,44 f.status,45 f.session_start,46 CASE47 WHEN f.session_end > (LEAD(session_start) OVER w) THEN48 (LEAD(session_start) OVER w) - '1 second'::INTERVAL49 ELSE f.session_end50 END AS session_end,51 f.rssi52 FROM (53 SELECT54 f.userid_key,55 f.ap_key,56 (array_agg(f.status ORDER BY f.session_start DESC))[1] AS status,57 min(f.session_start) AS session_start,58 max(f.session_end) AS session_end,59 CASE60 WHEN SUM((EXTRACT (EPOCH FROM f.session_duration))) = 0 THEN61 min(f.rssi)62 ELSE63 SUM(64 (EXTRACT (EPOCH FROM f.session_duration)) * f.rssi65 ) / SUM((EXTRACT (EPOCH FROM f.session_duration)))66 END AS rssi67 FROM (68 SELECT69 f.userid_key,70 f.ap_key,71 f.status,72 f.session_start,73 f.session_end,74 f.session_duration,75 f.rssi,76 SUM(next_within_delta) OVER (77 PARTITION BY f.userid_key 78 ORDER BY f.session_start79 RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING80 ) AS block81 FROM (82 SELECT83 f.userid_key,84 f.ap_key,85 f.status,86 f.session_start,87 f.session_end,88 f.session_duration,89 f.rssi,90 CASE91 WHEN92 (((LEAD(f.session_start) OVER w) - f.session_end) < '10 minutes') AND93 (((LEAD(f.ap_key) OVER w) = f.ap_key))94 THEN 095 ELSE 196 END AS next_within_delta97 FROM98 fact.session f,99 dimension.day d,100 dimension.userid_mac u,101 dimension.ap ap102 WHERE103 f.pulltime_last AND104 f.session_start_day_key = d.key AND105 d.pull_hours_missing = 0 AND106 f.userid_key = u.userid_key AND107 f.mac_key = u.mac_key AND108 f.session_start_day_key = u.day_key AND109 u.main = TRUE AND110 f.ap_key = ap.key AND111 ap.floor != 'N/A' AND112 ap.floor IS NOT null AND113 ap.building_key IS NOT null114 WINDOW w AS (PARTITION BY f.userid_key ORDER BY f.session_start)115 ) f116 ) f117 GROUP BY f.userid_key, f.ap_key, f.block118 ) f119 WINDOW w AS (PARTITION BY f.userid_key ORDER BY f.session_start)120 ) f121 )122 SELECT123 f.userid_key,124 f.ap_key,125 f.status,126 f.session_start,127 f.session_end,128 f.session_duration,129 f.rssi130 FROM f131 JOIN (132 SELECT f.userid_key FROM f GROUP BY f.userid_key133 HAVING NOT bool_or(f.session_duration > '24 hours')134 ) a135 ON f.userid_key = a.userid_key136 JOIN (137 SELECT f.userid_key, f.session_start138 FROM f139 GROUP BY f.userid_key, f.session_start140 HAVING COUNT(*) < 2141 ) b142 ON f.userid_key = b.userid_key AND f.session_start = b.session_start143 WHERE (f.session_end - f.session_start) > '10 minutes'144 ORDER BY f.session_start145 WITH NO DATA146 """147 )148 conn.execute(149 f"""150 CREATE UNIQUE INDEX IF NOT EXISTS ix_stationary_session_userid_key_session_start151 ON views.stationary_session (userid_key, session_start)152 """153 )154 conn.execute("REFRESH MATERIALIZED VIEW views.stationary_session")155def main(args):156 engine = create_engine(args.wifi_conn)157 logging.info("Creating materialized view of stationary sessions.")158 create_view(engine)159if __name__ == "__main__":160 cli = argparse.ArgumentParser(description="Create the stationary sessions view.")161 args = resolve_args(cli)...

Full Screen

Full Screen

nesteddictionaries.py

Source:nesteddictionaries.py Github

copy

Full Screen

1# Dealing with nested dictionaries2number_of_sessions = 03total_session_time = 04avg_session_time = 05total_dict = {}6user_dict = {}7stream_dict = {'session1': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 24, 'session_end': 44}},8'session2': {'name': 'Ethan Peck', 'userid':'ethpeck', 'sessioninfo': {'session_start': 30, 'session_end': 70}},9'session3': {'name': 'Aaron Peck', 'userid':'apeck14', 'sessioninfo': {'session_start': 4, 'session_end': 9}},10'session4': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 40, 'session_end': 45}},11'session5': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 20, 'session_end': 40}},12'session6': {'name': 'Tina Peck', 'userid':'tpeck13', 'sessioninfo': {'session_start': 11, 'session_end': 13}},13'session7': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 28, 'session_end': 40}},14'session8': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 20, 'session_end': 40}},15'session9': {'name': 'Ian Peck', 'userid':'apeck14', 'sessioninfo': {'session_start': 20, 'session_end': 23}},16'session10': {'name': 'Ethan Peck', 'userid':'ethpeck','sessioninfo': {'session_start': 20, 'session_end': 40}},17'session11': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 20, 'session_end': 40}},18'session12': {'name': 'Tina Peck', 'userid':'tpeck13', 'sessioninfo': {'session_start': 20, 'session_end': 40}},19'session13': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 80, 'session_end': 100}},20'session14': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 11, 'session_end': 12}},21'session15': {'name': 'Aaron Peck', 'userid':'apeck14', 'sessioninfo': {'session_start': 20, 'session_end': 40}},22'session16': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 13, 'session_end': 17}},23'session17': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 20, 'session_end': 30}},24'session18': {'name': 'Ethan Peck', 'userid':'ethpeck', 'sessioninfo': {'session_start': 10, 'session_end': 15}},25'session19': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 9, 'session_end': 42}},26'session20': {'name': 'Tina Peck', 'userid':'tpeck13', 'sessioninfo': {'session_start': 16, 'session_end': 40}},27'session21': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 20, 'session_end': 40}},28'session22': {'name': 'Ethan Peck', 'userid':'ethpeck', 'sessioninfo': {'session_start': 240, 'session_end': 400}},29'session23': {'name': 'Aaron Peck', 'userid':'apeck14', 'sessioninfo': {'session_start': 12, 'session_end': 90}},30'session24': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 20, 'session_end': 40}},31'session25': {'name': 'Tina Peck', 'userid':'tpeck13', 'sessioninfo': {'session_start': 1, 'session_end': 12}},32'session26': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 20, 'session_end': 40}},33'session27': {'name': 'Aaron Peck', 'userid':'apeck14', 'sessioninfo': {'session_start': 5, 'session_end': 7}},34'session28': {'name': 'Ian Peck', 'userid':'ianpeck22', 'sessioninfo': {'session_start': 12, 'session_end': 40}},35'session29': {'name': 'Tina Peck', 'userid':'tpeck13', 'sessioninfo': {'session_start': 100, 'session_end': 300}}}36def find_summed_info(dict):37 global number_of_sessions38 global total_session_time39 global avg_session_time40 number_of_sessions = len(list(dict.keys()))41 for v in dict.values():42 indv_session_time = v['sessioninfo']['session_end'] - v['sessioninfo']['session_start']43 total_session_time += indv_session_time44 avg_session_time = total_session_time / number_of_sessions45def create_nested_dict(dict):46 global user_dict47 user_list = []48 for v in dict.values():49 if v['userid'] not in user_list:50 user_list.append(v['userid'])51 for user in user_list:52 user_dict[user] = {}53 user_dict[user]['numberofsessions'] = 054 user_dict[user]['totalsessiontime'] = 055 user_dict[user]['avgsessiontime'] = 056def user_stats(dict):57 global user_dict58 for v in stream_dict.values():59 user_dict[v['userid']]['numberofsessions'] += 160 indv_session_time = v['sessioninfo']['session_end'] - v['sessioninfo']['session_start']61 user_dict[v['userid']]['totalsessiontime'] += indv_session_time62 63 for v in user_dict.values():64 v['avgsessiontime'] = v['totalsessiontime'] / v['numberofsessions']65find_summed_info(stream_dict)66total_dict['avg_session_time'] = avg_session_time67total_dict['number_of_sessions'] = number_of_sessions68total_dict['total_session_time'] = total_session_time69print('total dict: ',total_dict)70create_nested_dict(stream_dict)71print(user_dict)72user_stats(stream_dict)...

Full Screen

Full Screen

update_telemetry_session_details.py

Source:update_telemetry_session_details.py Github

copy

Full Screen

...33 self.discriminator = None34 if session_end is not None:35 self.session_end = session_end36 @property37 def session_end(self):38 """Gets the session_end of this UpdateTelemetrySessionDetails. # noqa: E50139 The end time for this telemetry session # noqa: E50140 :return: The session_end of this UpdateTelemetrySessionDetails. # noqa: E50141 :rtype: datetime42 """43 return self._session_end44 @session_end.setter45 def session_end(self, session_end):46 """Sets the session_end of this UpdateTelemetrySessionDetails.47 The end time for this telemetry session # noqa: E50148 :param session_end: The session_end of this UpdateTelemetrySessionDetails. # noqa: E50149 :type: datetime50 """51 self._session_end = session_end52 def to_dict(self):53 """Returns the model properties as a dict"""54 result = {}55 for attr, _ in six.iteritems(self.openapi_types):56 value = getattr(self, attr)57 if isinstance(value, list):58 result[attr] = list(map(59 lambda x: x.to_dict() if hasattr(x, "to_dict") else x,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful