Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Brookins abrookins

View GitHub Profile
@abrookins
abrookins / kant-light.icls
Last active Aug 12, 2020
Kant Light - A light monochrome color scheme for Intellij editors. Inspired by Verdandi.
View kant-light.icls
Moved to: https://github.com/abrookins/kant
@abrookins
abrookins / kant-dark.icls
Last active Aug 12, 2020
Kant Dark - A dark monochrome color scheme for Intellij editors. Inspired by Verdandi.
View kant-dark.icls
Moved to: https://github.com/abrookins/kant
@abrookins
abrookins / kant-light.icls
Created Aug 11, 2020
Kant Light - A light monochrome color scheme for Intellij editors.
View kant-light.icls
This file has been truncated, but you can view the full file.
<scheme name="Kant" version="142" parent_scheme="Default">
<option name="FONT_SCALE" value="1.0" />
<metaInfo>
<property name="created">2020-08-11T14:43:37</property>
<property name="ide">Python</property>
<property name="ideVersion">2020.2.0.0</property>
<property name="modified">2020-08-11T14:43:46</property>
<property name="originalScheme">Kant</property>
</metaInfo>
View schema.py
SiteStatsSchema = marshmallow_dataclass.class_schema(SiteStats)
View ipython3.py
In [13]: SiteStatsSchema().load({"meter_reading_count": "hey"})
[…]
ValidationError: {'meter_reading_count': ['Not a valid integer.'], 'min_wh_generated': ['Missing data for required field.'], 'last_reporting_time': ['Missing data for required field.'], 'max_wh_generated': ['Missing data for required field.'], 'max_capacity': ['Missing data for required field.']}
View ipython3.py
In [10]: stats2 = SiteStatsSchema().load(data)
In [11]: stats == stats2
Out[11]: True
View ipython2.py
In [8]: data = SiteStatsSchema().dump(stats)
In [9]: data
Out[9]:
{'meter_reading_count': 5,
'min_wh_generated': 1.0,
'last_reporting_time': '2020-07-31T15:08:45.109063',
'max_wh_generated': 22.0,
'max_capacity': 100.0}
View ipython1.py
In [3]: import datetime
In [4]: now = datetime.datetime.now()
In [5]: stats = SiteStats(last_reporting_time=now, meter_reading_count=5, max_wh_generated=22, min_wh_generated=1, max_capacity=100)
In [6]: stats
Out[6]: SiteStats(last_reporting_time=datetime.datetime(2020, 7, 31, 15, 8, 45, 109063), meter_reading_count=5, max_wh_generated=22, min_wh_generated=1, max_capacity=100)
View site_stats.py
@dataclass(frozen=True, eq=True)
class SiteStats:
"""Reporting stats for a site."""
last_reporting_time: datetime.datetime
meter_reading_count: int
max_wh_generated: float
min_wh_generated: float
max_capacity: float
View peewee.py
from peewee import *
import datetime
db = SqliteDatabase('my_database.db')
class User(Model):
username = CharField(unique=True)
You can’t perform that action at this time.