This commit is contained in:
Harris Minhas 2023-08-02 04:19:52 +00:00 committed by GitHub
commit 7a16a0bc68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -15,6 +15,6 @@ while True:
timestamp = datetime.datetime.now()
print(timestamp)
db.insert([
CPUStats(timestamp=timestamp, cpu_id=cpu_id, cpu_percent=cpu_percent)
CPUStats(timestamp=timestamp, cpu_id=cpu_id, cpu_percent=cpu_percent, working_status=True)
for cpu_id, cpu_percent in enumerate(stats)
])

View File

@ -1,4 +1,4 @@
from infi.clickhouse_orm import Model, DateTimeField, UInt16Field, Float32Field, Memory
from infi.clickhouse_orm import Model, DateTimeField, UInt16Field, Float32Field, Memory, BooleanField
class CPUStats(Model):
@ -6,6 +6,7 @@ class CPUStats(Model):
timestamp = DateTimeField()
cpu_id = UInt16Field()
cpu_percent = Float32Field()
working_status = BooleanField()
engine = Memory()

View File

@ -162,6 +162,24 @@ class FixedStringField(StringField):
if len(value) > self._length:
raise ValueError('Value of %d bytes is too long for FixedStringField(%d)' % (len(value), self._length))
class BooleanField(Field):
# The ClickHouse column type to use
db_type = 'Bool'
# The default value
class_default = False
def to_python(self, value, timezone_in_use):
# Convert valid values to bool
if value in (1, '1', True):
return True
elif value in (0, '0', False):
return False
else:
raise ValueError('Invalid value for BooleanField: %r' % value)
def to_db_string(self, value, quote=True):
# The value was already converted by to_python, so it's a bool
return '1' if value else '0'
class DateField(Field):