This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const iconWindowHTML = (data, iconsData) => { | |
const iconWindowElement = document.createElement('div'); | |
iconWindowElement.classList.add('card', 'marker-window'); | |
const iconsHTML = Object.values(iconsData).map(iconData => { | |
if(!iconData?.icon){ | |
return ''; | |
} | |
return ` | |
<div class="d-flex flex-column align-items-center mr-1"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// html for the marker | |
const iconHTML = (attr,percent,value,colors,unit) => { | |
if(attr === "battery"){ | |
return ` | |
<div title="${value}${unit}" class="marker"> | |
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="30" viewBox="0 0 55 120"> | |
<rect x="10" y="7" width="45" height="102" stroke="black" fill="white" stroke-width="5"/> | |
<rect x="12" y="${107-percent}" width="40" height="${percent + 1}" stroke="black" fill="${colors.background}" stroke-width="0"/> | |
<rect x="12" y="30" width="20" height="4" fill="black" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const buildIcon = (data,attr) => { | |
const value = data.attributeValues?.[attr]; | |
const meta = data.attributes?.find(a => a.name === attr); | |
if(!value || !meta){ | |
throw new TypeError('Missing values'); // value at this point is string, so "0" won't fail | |
} | |
const min = meta.attributeTags?.min ? Number(meta.attributeTags.min) : 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set up individual marker | |
const setUpMarker = (id, data) => { | |
if(!data.attributeValues?.location){ | |
return false; | |
} | |
// Pull marker from dictionary, or create new | |
let marker = markers[id]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Excerpt from https://github.com/Losant/google-map-advanced-markers/blob/main/custom-head-content.html | |
// Initialize globals | |
const markers = {}; | |
let devices = []; | |
let map; | |
let numSelected = 0; | |
let AdvancedMarkerElement; | |
let bounds; | |
let selectedAttribute = $('#attribute-selector').val() || 'battery'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def export_summary(summary_series, file_name=SUMMARY_OUTPUT_FILE): | |
directory = get_output_directory() | |
output = pd.DataFrame(summary_series).transpose() | |
output.rename(columns={"25%": "25th", "50%": "50th", "75%": "75th"},inplace=True) | |
output.to_csv(os.path.join(directory, file_name),index=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import importlib | |
nb = importlib.import_module("ipynb.fs.defs.battery-stats") | |
remove_consecutive_same_values = nb.remove_consecutive_same_values | |
def build_battery_history(values, device_id="60df87b4be3fc900069dac1f", start_time=1600000000000): | |
id_array = [device_id] * len(values) | |
timestamp_array = map(lambda t: start_time + t * 10000, range(len(values))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import importlib | |
nb = importlib.import_module("ipynb.fs.defs.battery-stats") | |
is_row_before_charging = nb.is_row_before_charging | |
# it should return True if the change from the previous row is positive (isn't charging) | |
# and the change to the next row is negative (will be charging) | |
about_to_charge = pd.DataFrame({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import importlib | |
nb = importlib.import_module("ipynb.fs.defs.battery-stats") | |
get_rows_before_charging = nb.get_rows_before_charging | |
def build_battery_history(values, device_id="60df87b4be3fc900069dac1f", start_time=1600000000000): | |
id_array = [device_id] * len(values) | |
timestamp_array = map(lambda t: start_time + t * 10000, range(len(values))) | |
return pd.DataFrame({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_row_before_charging(row): | |
return (row.battery_loss_next_row < 0) and (row.battery_loss_this_row > 0) | |
def remove_consecutive_same_values(df): | |
df['is_new_value'] = df.groupby(['ID'])['battery'].shift(1) != df['battery'] | |
return df.loc[df['is_new_value']] | |
def get_rows_before_charging(df): | |
# sorting not necessary, but is much easier to follow during dev | |
# df.sort_values(by=['ID','Timestamp'],inplace=True) |
NewerOlder