Skip to content

Commit

Permalink
feat: Added field time_window_enabled for prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
supradeep2819 committed Jun 18, 2024
1 parent a5fea59 commit e3b9f73
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
18 changes: 18 additions & 0 deletions core/migrations/0034_prompt_time_window_enabled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.5 on 2024-06-18 11:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0033_prompt_time_grain_enabled'),
]

operations = [
migrations.AddField(
model_name='prompt',
name='time_window_enabled',
field=models.BooleanField(default=True),
),
]
33 changes: 20 additions & 13 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,14 @@ class Credential(models.Model):

def __str__(self):
return f"{self.connector}: {self.connector_config} : {self.workspace}: {self.id} : {self.name}"


class StorageCredentials(models.Model):
id = models.UUIDField(primary_key=True, editable=False, default=uuid.UUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"))
workspace = models.ForeignKey(to=Workspace, on_delete=models.CASCADE, related_name="storage_credentials")
connector_config = models.JSONField(blank=False, null=False)


class Source(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
Expand Down Expand Up @@ -135,29 +136,34 @@ class Connector(models.Model):


class Package(models.Model):
name = models.CharField(primary_key=True,max_length=256, null=False, blank=False)
name = models.CharField(primary_key=True, max_length=256, null=False, blank=False)
scopes = ArrayField(models.CharField(max_length=64), blank=True, default=list)
gated = models.BooleanField(null=False, blank = False, default=True)
gated = models.BooleanField(null=False, blank=False, default=True)


class Prompt(models.Model):
id = models.UUIDField(primary_key=True, editable=False, default=uuid.UUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"))
name = models.CharField(max_length=256, null=False, blank=False,unique=True)
description = models.CharField(max_length=1000, null=False, blank=False,default="aaaaaa")
type = models.CharField(null=False, blank = False,max_length=256, default="SRC_SHOPIFY")
name = models.CharField(max_length=256, null=False, blank=False, unique=True)
description = models.CharField(max_length=1000, null=False, blank=False, default="aaaaaa")
type = models.CharField(null=False, blank=False, max_length=256, default="SRC_SHOPIFY")
# spec = models.JSONField(blank=False, null=True)
filters = models.JSONField(default=dict)
operators = models.JSONField(default={
'string': ["=", "!=", "IN", "NOT IN"],
'integer': ["=", ">", "<", ">=", "<=", "!="]
})
query = models.CharField(max_length=1000,null=False, blank=False,default="query")
package_id = models.CharField(null=False, blank = False,max_length=20,default="P0")
gated = models.BooleanField(null=False, blank = False, default=True)
query = models.CharField(max_length=1000, null=False, blank=False, default="query")
package_id = models.CharField(null=False, blank=False, max_length=20, default="P0")
gated = models.BooleanField(null=False, blank=False, default=True)
time_grain_enabled = models.BooleanField(null=False, blank=False, default=False)
time_window_enabled = models.BooleanField(null=False, blank=False, default=True)


class SourceAccessInfo(models.Model):
source = models.ForeignKey(to=Source, on_delete=models.CASCADE, related_name="source_access_info",primary_key=True)
storage_credentials = models.ForeignKey(to=StorageCredentials,on_delete=models.CASCADE,related_name="source_access_info")
source = models.ForeignKey(to=Source, on_delete=models.CASCADE, related_name="source_access_info", primary_key=True)
storage_credentials = models.ForeignKey(
to=StorageCredentials, on_delete=models.CASCADE, related_name="source_access_info")


class Account(models.Model):
id = models.UUIDField(primary_key=True, editable=False, default=uuid.UUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"))
Expand All @@ -172,14 +178,15 @@ class Explore(models.Model):
created_at = models.DateTimeField(default=timezone.now)
updated_at = models.DateTimeField(auto_now=True)
id = models.UUIDField(primary_key=True, editable=False, default=uuid.UUID("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"))
name = models.CharField(max_length=256, null=False, blank=False,default="aaaaaa")
name = models.CharField(max_length=256, null=False, blank=False, default="aaaaaa")
workspace = models.ForeignKey(to=Workspace, on_delete=models.CASCADE, related_name="explore_workspace")
prompt = models.ForeignKey(to=Prompt, on_delete=models.CASCADE, related_name="explore_prompt")
sync = models.ForeignKey(to=Sync, on_delete=models.CASCADE, related_name="explore_sync")
ready = models.BooleanField(null=False, blank = False, default=False)
ready = models.BooleanField(null=False, blank=False, default=False)
account = models.ForeignKey(to=Account, on_delete=models.CASCADE, related_name="explore_account")
spreadsheet_url = models.URLField(null=True, blank=True, default="https://example.com")


class ValmiUserIDJitsuApiToken(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
api_token = models.CharField(max_length=256, blank=True, null=True)
Expand Down
8 changes: 5 additions & 3 deletions core/schemas/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ class TimeWindowRange(Schema):


class TimeWindow(Schema):
label: str
range: TimeWindowRange
label: Optional[str]
range: Optional[TimeWindowRange]


class TimeGrain(str, Enum):
day = 'day'
day = 'day'
week = 'week'
month = 'month'

def members():
return TimeGrain._member_names_

Expand Down
12 changes: 8 additions & 4 deletions core/services/prompt_templates/prompts.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
{%- if filterStr != "" -%}
{% assign filterStr = filterStr | append: " and " %}
{%- endif -%}
{%- if timeWindow.range.start contains "now()" -%}
{{ filterStr }} "updated_at" >= {{ timeWindow.range.start }} and "updated_at" <= {{ timeWindow.range.end }}
{%- if timeWindow.label != nil and timeWindow.range != nil -%}
{%- if "now()" in timeWindow.range.start -%}
{{ filterStr }} "updated_at" >= {{ timeWindow.range.start }} and "updated_at" <= {{ timeWindow.range.end }}
{%- else -%}
{{ filterStr }} "updated_at" >= '{{ timeWindow.range.start }}' and "updated_at" <= '{{ timeWindow.range.end }}'
{%- endif -%}
{%- else -%}
{{ filterStr }} "updated_at" >= '{{ timeWindow.range.start }}' and "updated_at" <= '{{ timeWindow.range.end }}'
{%- endif -%}
{{ filterStr }} 1=1
{%- endif -%}
3 changes: 2 additions & 1 deletion init_db/prompt_def.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
},
"type": "SRC_SHOPIFY",
"package_id": "P0",
"gated": true
"gated": true,
"time_window_enabled":false
},

{
Expand Down

0 comments on commit e3b9f73

Please sign in to comment.