Skip to content

Commit 50add0a

Browse files
committed
feat(frontend): implement Measure AI chat
closes #2725
1 parent 239e0a8 commit 50add0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+17745
-5159
lines changed

backend/api/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func main() {
133133
teams.GET(":id/members", measure.GetTeamMembers)
134134
teams.DELETE(":id/members/:memberId", measure.RemoveTeamMember)
135135
teams.GET(":id/usage", measure.GetUsage)
136+
teams.POST(":id/usage/ai", measure.ReportAiUsage)
136137
teams.GET(":id/slack", measure.GetTeamSlack)
137138
teams.PATCH(":id/slack/status", measure.UpdateTeamSlackStatus)
138139
}

backend/api/measure/event.go

Lines changed: 100 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,16 +1519,6 @@ func GetExceptionsWithFilter(ctx context.Context, group *group.ExceptionGroup, a
15191519
return
15201520
}
15211521

1522-
selectedVersions, err := af.VersionPairs()
1523-
if err != nil {
1524-
return
1525-
}
1526-
1527-
selectedOSVersions, err := af.OSVersionPairs()
1528-
if err != nil {
1529-
return
1530-
}
1531-
15321522
timeformat := "2006-01-02T15:04:05.000"
15331523
var keyTimestamp string
15341524
if !af.KeyTimestamp.IsZero() {
@@ -1552,19 +1542,56 @@ func GetExceptionsWithFilter(ctx context.Context, group *group.ExceptionGroup, a
15521542
Select("exception.framework framework").
15531543
Select("attachments").
15541544
Select(fmt.Sprintf("row_number() over (order by timestamp %s, id) as row_num", order)).
1555-
Clause(prewhere, af.AppID, group.ID).
1556-
Where("(attribute.app_version, attribute.app_build) in (?)", selectedVersions.Parameterize()).
1557-
Where("(attribute.os_name, attribute.os_version) in (?)", selectedOSVersions.Parameterize()).
1558-
Where("type = ?", event.TypeException).
1559-
Where("exception.handled = false").
1560-
Where("inet.country_code in ?", af.Countries).
1561-
Where("attribute.device_name in ?", af.DeviceNames).
1562-
Where("attribute.device_manufacturer in ?", af.DeviceManufacturers).
1563-
Where("attribute.device_locale in ?", af.Locales).
1564-
Where("attribute.network_type in ?", af.NetworkTypes).
1565-
Where("attribute.network_provider in ?", af.NetworkProviders).
1566-
Where("attribute.network_generation in ?", af.NetworkGenerations).
1567-
Where("timestamp >= ? and timestamp <= ?", af.From, af.To)
1545+
Clause(prewhere, af.AppID, group.ID)
1546+
1547+
if len(af.Versions) > 0 {
1548+
substmt.Where("attribute.app_version").In(af.Versions)
1549+
}
1550+
1551+
if len(af.VersionCodes) > 0 {
1552+
substmt.Where("attribute.app_build").In(af.VersionCodes)
1553+
}
1554+
1555+
if len(af.OsNames) > 0 {
1556+
substmt.Where("attribute.os_name").In(af.OsNames)
1557+
}
1558+
1559+
if len(af.OsVersions) > 0 {
1560+
substmt.Where("attribute.os_version").In(af.OsVersions)
1561+
}
1562+
1563+
substmt.Where("type = ?", event.TypeException).
1564+
Where("exception.handled = false")
1565+
1566+
if len(af.Countries) > 0 {
1567+
substmt.Where("inet.country_code in ?", af.Countries)
1568+
}
1569+
1570+
if len(af.DeviceNames) > 0 {
1571+
substmt.Where("attribute.device_name in ?", af.DeviceNames)
1572+
}
1573+
1574+
if len(af.DeviceManufacturers) > 0 {
1575+
substmt.Where("attribute.device_manufacturer in ?", af.DeviceManufacturers)
1576+
}
1577+
1578+
if len(af.Locales) > 0 {
1579+
substmt.Where("attribute.device_locale in ?", af.Locales)
1580+
}
1581+
1582+
if len(af.NetworkTypes) > 0 {
1583+
substmt.Where("attribute.network_type in ?", af.NetworkTypes)
1584+
}
1585+
1586+
if len(af.NetworkProviders) > 0 {
1587+
substmt.Where("attribute.network_provider in ?", af.NetworkProviders)
1588+
}
1589+
1590+
if len(af.NetworkGenerations) > 0 {
1591+
substmt.Where("attribute.network_generation in ?", af.NetworkGenerations)
1592+
}
1593+
1594+
substmt.Where("timestamp >= ? and timestamp <= ?", af.From, af.To)
15681595

15691596
if af.HasUDExpression() && !af.UDExpression.Empty() {
15701597
subQuery := sqlf.From("user_def_attrs").
@@ -1792,16 +1819,6 @@ func GetANRsWithFilter(ctx context.Context, group *group.ANRGroup, af *filter.Ap
17921819
return
17931820
}
17941821

1795-
selectedVersions, err := af.VersionPairs()
1796-
if err != nil {
1797-
return
1798-
}
1799-
1800-
selectedOSVersions, err := af.OSVersionPairs()
1801-
if err != nil {
1802-
return
1803-
}
1804-
18051822
timeformat := "2006-01-02T15:04:05.000"
18061823
var keyTimestamp string
18071824
if !af.KeyTimestamp.IsZero() {
@@ -1824,18 +1841,56 @@ func GetANRsWithFilter(ctx context.Context, group *group.ANRGroup, af *filter.Ap
18241841
Select("anr.threads threads").
18251842
Select("attachments").
18261843
Select(fmt.Sprintf("row_number() over (order by timestamp %s, id) as row_num", order)).
1827-
Clause(prewhere, af.AppID, group.ID).
1828-
Where("(attribute.app_version, attribute.app_build) in (?)", selectedVersions.Parameterize()).
1829-
Where("(attribute.os_name, attribute.os_version) in (?)", selectedOSVersions.Parameterize()).
1830-
Where("type = ?", event.TypeANR).
1831-
Where("inet.country_code in ?", af.Countries).
1832-
Where("attribute.device_name in ?", af.DeviceNames).
1833-
Where("attribute.device_manufacturer in ?", af.DeviceManufacturers).
1834-
Where("attribute.device_locale in ?", af.Locales).
1835-
Where("attribute.network_type in ?", af.NetworkTypes).
1836-
Where("attribute.network_provider in ?", af.NetworkProviders).
1837-
Where("attribute.network_generation in ?", af.NetworkGenerations).
1838-
Where("timestamp >= ? and timestamp <= ?", af.From, af.To)
1844+
Clause(prewhere, af.AppID, group.ID)
1845+
1846+
if len(af.Versions) > 0 {
1847+
substmt.Where("attribute.app_version").In(af.Versions)
1848+
}
1849+
1850+
if len(af.VersionCodes) > 0 {
1851+
substmt.Where("attribute.app_build").In(af.VersionCodes)
1852+
}
1853+
1854+
if len(af.OsNames) > 0 {
1855+
substmt.Where("attribute.os_name").In(af.OsNames)
1856+
}
1857+
1858+
if len(af.OsVersions) > 0 {
1859+
substmt.Where("attribute.os_version").In(af.OsVersions)
1860+
}
1861+
1862+
substmt.Where("type = ?", event.TypeANR).
1863+
Where("anr.handled = false")
1864+
1865+
if len(af.Countries) > 0 {
1866+
substmt.Where("inet.country_code in ?", af.Countries)
1867+
}
1868+
1869+
if len(af.DeviceNames) > 0 {
1870+
substmt.Where("attribute.device_name in ?", af.DeviceNames)
1871+
}
1872+
1873+
if len(af.DeviceManufacturers) > 0 {
1874+
substmt.Where("attribute.device_manufacturer in ?", af.DeviceManufacturers)
1875+
}
1876+
1877+
if len(af.Locales) > 0 {
1878+
substmt.Where("attribute.device_locale in ?", af.Locales)
1879+
}
1880+
1881+
if len(af.NetworkTypes) > 0 {
1882+
substmt.Where("attribute.network_type in ?", af.NetworkTypes)
1883+
}
1884+
1885+
if len(af.NetworkProviders) > 0 {
1886+
substmt.Where("attribute.network_provider in ?", af.NetworkProviders)
1887+
}
1888+
1889+
if len(af.NetworkGenerations) > 0 {
1890+
substmt.Where("attribute.network_generation in ?", af.NetworkGenerations)
1891+
}
1892+
1893+
substmt.Where("timestamp >= ? and timestamp <= ?", af.From, af.To)
18391894

18401895
if af.HasUDExpression() && !af.UDExpression.Empty() {
18411896
subQuery := sqlf.From("user_def_attrs").

backend/api/measure/session.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -379,21 +379,9 @@ func GetSessionsWithFilter(ctx context.Context, af *filter.AppFilter) (sessions
379379
stmt.SubQuery("session_id in (", ")", subQuery)
380380
}
381381

382-
applyGroupBy := af.Crash ||
383-
af.ANR ||
384-
af.HasCountries() ||
385-
af.HasNetworkProviders() ||
386-
af.HasNetworkTypes() ||
387-
af.HasNetworkGenerations() ||
388-
af.HasDeviceLocales() ||
389-
af.HasDeviceManufacturers() ||
390-
af.HasDeviceNames()
391-
392-
if applyGroupBy {
393-
stmt.GroupBy("session_id")
394-
stmt.GroupBy("first_event_timestamp")
395-
stmt.GroupBy("last_event_timestamp")
396-
}
382+
stmt.GroupBy("session_id")
383+
stmt.GroupBy("first_event_timestamp")
384+
stmt.GroupBy("last_event_timestamp")
397385

398386
defer stmt.Close()
399387

@@ -499,6 +487,7 @@ func GetSessionsWithFilter(ctx context.Context, af *filter.AppFilter) (sessions
499487
// set matched free text results
500488
sess.MatchedFreeText = session.ExtractMatches(af.FreeText, sess.Attribute.UserID, sess.SessionID.String(), uniqueTypes, uniqueStrings, uniqueViewClassnames, uniqueSubviewClassnames, uniqueExceptions, uniqueANRs, uniqueClickTargets, uniqueLongclickTargets, uniqueScrollTargets)
501489

490+
fmt.Println("Matched Free Text:", sess.MatchedFreeText)
502491
sessions = append(sessions, sess)
503492
}
504493

0 commit comments

Comments
 (0)