Compare commits

..

10 Commits

7 changed files with 176 additions and 132 deletions

18
models/amendment.go Normal file
View File

@@ -0,0 +1,18 @@
package models
import "time"
type DBAmendment struct {
Id int `gorm:"index"`
IndexColumn string `gorm:"primaryKey;index"`
IndexId string `gorm:"primaryKey;index"`
Table string `gorm:"primaryKey;index"`
AmendmentColumn string
AmendmentValue string
Requestor string
Timestamp time.Time
}
func (DBConversation) TableName() string {
return "gc_amendments"
}

View File

@@ -19,8 +19,11 @@ type DBConversation struct {
Start *time.Time `gorm:"index"`
UtilizationLabelId *string
LiveUpdate *time.Time
DetailsUpdate *time.Time
SemiLiveUpdate *time.Time
JobUpdate *time.Time
Participants []DBParticipant `gorm:"foreignKey:ConversationId;references:Id"`
}
func (DBConversation) TableName() string {

View File

@@ -20,6 +20,8 @@ type DBParticipant struct {
Wrapup *string `gorm:"type:json"`
WrapupExpected *bool
WrapupRequired *bool
Sessions []DBSession `gorm:"foreignKey:ParticipantId;references:Id"`
}
func (DBParticipant) TableName() string {

View File

@@ -7,6 +7,7 @@ type DBQueueLog struct {
ConversationId string `gorm:"primaryKey"`
Start time.Time `gorm:"index"`
End time.Time `gorm:"index"`
Duration float64
Result string `gorm:"type:json"`
}

View File

@@ -1,5 +1,10 @@
package models
type AnalyticsConversationWithAttributesQuery struct {
Conversations []AnalyticsConversationWithAttributes `json:"conversations"`
Cursor *string `json:"cursor"`
}
type AnalyticsConversationWithAttributes struct {
ConversationEnd string `json:"conversationEnd"`
ConversationId string `json:"conversationId"`
@@ -88,6 +93,20 @@ type AnalyticsConversationWithoutAttributes struct {
Q850ResponseCodes []int `json:"q850ResponseCodes"`
Conference bool `json:"conference"`
} `json:"segments"`
Flow struct {
EndingLanguage string `json:"endingLanguage"`
EntryReason string `json:"entryReason"`
EntryType string `json:"entryType"`
ExitReason string `json:"exitReason"`
FlowId string `json:"flowId"`
FlowName string `json:"flowName"`
FlowType string `json:"flowType"`
FlowVersion string `json:"flowVersion"`
StartingLanguage string `json:"startingLanguage"`
TransferTargetAddress string `json:"transferTargetAddress"`
TransferTargetName string `json:"transferTargetName"`
TransferType string `json:"transferType"`
} `json:"flow"`
Metrics []struct {
Name string `json:"name"`
Value int `json:"value"`

View File

@@ -15,6 +15,9 @@ type DBSession struct {
Recording bool
RemoteNameDisplayable string
SessionDnis string
Flow string `gorm:"type:json"`
Segments []DBSegment `gorm:"foreignKey:SessionId;references:Id"`
}
func (DBSession) TableName() string {

View File

@@ -33,8 +33,6 @@ func ExtractWithoutAttributes(base models.AnalyticsConversationWithoutAttributes
}
divisionIdsBytesStr := string(divisionIdsBytes)
currentTime := time.Now()
conversation := models.DBConversation{
DivisionIds: &divisionIdsBytesStr,
End: endTime,
@@ -43,7 +41,6 @@ func ExtractWithoutAttributes(base models.AnalyticsConversationWithoutAttributes
MinRFactor: &base.MediaStatsMinConversationRFactor,
OriginatingDirection: &base.OriginatingDirection,
Start: startTime,
SemiLiveUpdate: &currentTime,
}
var participants []models.DBParticipant
var sessions []models.DBSession
@@ -73,6 +70,11 @@ func ExtractWithoutAttributes(base models.AnalyticsConversationWithoutAttributes
metricsBytes = nil
}
flowBytes, err := json.Marshal(sess.Flow)
if err != nil {
flowBytes = nil
}
session := models.DBSession{
Ani: sess.ANI,
Direction: sess.Direction,
@@ -88,6 +90,7 @@ func ExtractWithoutAttributes(base models.AnalyticsConversationWithoutAttributes
Recording: sess.Recording,
RemoteNameDisplayable: sess.RemoteNameDisplayable,
SessionDnis: sess.SessionDNIS,
Flow: string(flowBytes),
}
sessions = append(sessions, session)
@@ -116,7 +119,7 @@ func ExtractWithoutAttributes(base models.AnalyticsConversationWithoutAttributes
SegmentEnd: segmentEnd,
SegmentStart: segmentStart,
SegmentType: seg.SegmentType,
SessionId: sess.SessionId,
SessionId: session.Id,
WrapUpCode: seg.WrapUpCode,
}
@@ -129,7 +132,6 @@ func ExtractWithoutAttributes(base models.AnalyticsConversationWithoutAttributes
}
func ExtractLive(base models.NotificationConversationWithAttributes) (models.DBConversation, []models.DBParticipant, []models.DBCall) {
currentTime := time.Now()
conversation := models.DBConversation{
Id: base.Id,
@@ -138,7 +140,6 @@ func ExtractLive(base models.NotificationConversationWithAttributes) (models.DBC
RecordingState: &base.RecordingState,
SecurePause: &base.SecurePause,
UtilizationLabelId: &base.UtilizationLabelId,
LiveUpdate: &currentTime,
}
var participants []models.DBParticipant
@@ -260,128 +261,125 @@ func ExtractLive(base models.NotificationConversationWithAttributes) (models.DBC
}
func ExtractWithAttributes(base models.AnalyticsConversationWithAttributes) (models.DBConversation, []models.DBParticipant, []models.DBSession, []models.DBSegment) {
var startTime *time.Time
parsedStartTime, err := time.Parse(time.RFC3339, base.ConversationStart)
if err != nil {
startTime = nil
} else {
startTime = &parsedStartTime
}
var endTime *time.Time
parsedEndTime, err := time.Parse(time.RFC3339, base.ConversationEnd)
if err != nil {
endTime = nil
} else {
endTime = &parsedEndTime
}
divisionIdsBytes, err := json.Marshal(base.DivisionIds)
if err != nil {
divisionIdsBytes = nil
}
divisionIdsBytesStr := string(divisionIdsBytes)
currentTime := time.Now()
conversation := models.DBConversation{
DivisionIds: &divisionIdsBytesStr,
End: endTime,
Id: base.ConversationId,
MinMos: &base.MediaStatsMinConversationMos,
MinRFactor: &base.MediaStatsMinConversationRFactor,
OriginatingDirection: &base.OriginatingDirection,
Start: startTime,
JobUpdate: &currentTime,
}
var participants []models.DBParticipant
var sessions []models.DBSession
var segments []models.DBSegment
for _, p := range base.Participants {
attributesBytes, err := json.Marshal(p.Attributes)
if err != nil {
attributesBytes = nil
}
attributesBytesStr := string(attributesBytes)
participant := models.DBParticipant{
ConnectedTime: nil,
ConversationId: base.ConversationId,
EndTime: nil,
ExternalContactId: &p.ExternalContactId,
Id: p.ParticipantId,
Name: &p.ParticipantName,
Purpose: &p.Purpose,
Attributes: &attributesBytesStr,
}
participants = append(participants, participant)
for _, sess := range p.Sessions {
mediaEndpointStatsBytes, err := json.Marshal(sess.MediaEndpointStats)
if err != nil {
mediaEndpointStatsBytes = nil
}
metricsBytes, err := json.Marshal(sess.Metrics)
if err != nil {
metricsBytes = nil
}
session := models.DBSession{
Ani: sess.ANI,
Direction: sess.Direction,
Dnis: sess.DNIS,
EdgeId: sess.EdgeId,
Id: fmt.Sprintf("%s_%s", p.ParticipantId, sess.SessionId),
MediaEndpointStats: string(mediaEndpointStatsBytes),
MediaType: sess.MediaType,
Metrics: string(metricsBytes),
ParticipantId: p.ParticipantId,
ProtocolCallId: sess.ProtocolCallId,
Provider: sess.Provider,
Recording: sess.Recording,
RemoteNameDisplayable: sess.RemoteNameDisplayable,
SessionDnis: sess.SessionDnis,
}
sessions = append(sessions, session)
for _, seg := range sess.Segments {
segmentStart, err := time.Parse(time.RFC3339, seg.SegmentStart)
if err != nil {
segmentStart = time.Now()
}
segmentEnd, err := time.Parse(time.RFC3339, seg.SegmentEnd)
if err != nil {
segmentEnd = time.Now()
}
q850ResponseCodesBytes, err := json.Marshal(seg.Q850ResponseCodes)
if err != nil {
q850ResponseCodesBytes = nil
}
segment := models.DBSegment{
Id: fmt.Sprintf("%s_%s", session.Id, seg.SegmentType),
Conference: seg.Conference,
DisconnectType: seg.DisconnectType,
Q850ResponseCodes: string(q850ResponseCodesBytes),
SegmentEnd: segmentEnd,
SegmentStart: segmentStart,
SegmentType: seg.SegmentType,
SessionId: sess.SessionId,
WrapUpCode: seg.WrapUpCode,
}
segments = append(segments, segment)
}
}
}
return conversation, participants, sessions, segments
}
//func ExtractWithAttributes(base models.AnalyticsConversationWithAttributes) (models.DBConversation, []models.DBParticipant, []models.DBSession, []models.DBSegment) {
//
// var startTime *time.Time
// parsedStartTime, err := time.Parse(time.RFC3339, base.ConversationStart)
// if err != nil {
// startTime = nil
// } else {
// startTime = &parsedStartTime
// }
//
// var endTime *time.Time
// parsedEndTime, err := time.Parse(time.RFC3339, base.ConversationEnd)
// if err != nil {
// endTime = nil
// } else {
// endTime = &parsedEndTime
// }
//
// divisionIdsBytes, err := json.Marshal(base.DivisionIds)
// if err != nil {
// divisionIdsBytes = nil
// }
// divisionIdsBytesStr := string(divisionIdsBytes)
//
// conversation := models.DBConversation{
// DivisionIds: &divisionIdsBytesStr,
// End: endTime,
// Id: base.ConversationId,
// MinMos: &base.MediaStatsMinConversationMos,
// MinRFactor: &base.MediaStatsMinConversationRFactor,
// OriginatingDirection: &base.OriginatingDirection,
// Start: startTime,
// }
// var participants []models.DBParticipant
// var sessions []models.DBSession
// var segments []models.DBSegment
//
// for _, p := range base.Participants {
//
// attributesBytes, err := json.Marshal(p.Attributes)
// if err != nil {
// attributesBytes = nil
// }
// attributesBytesStr := string(attributesBytes)
//
// participant := models.DBParticipant{
// ConnectedTime: nil,
// ConversationId: base.ConversationId,
// EndTime: nil,
// ExternalContactId: &p.ExternalContactId,
// Id: p.ParticipantId,
// Name: &p.ParticipantName,
// Purpose: &p.Purpose,
// Attributes: &attributesBytesStr,
// }
// participants = append(participants, participant)
//
// for _, sess := range p.Sessions {
// mediaEndpointStatsBytes, err := json.Marshal(sess.MediaEndpointStats)
// if err != nil {
// mediaEndpointStatsBytes = nil
// }
//
// metricsBytes, err := json.Marshal(sess.Metrics)
// if err != nil {
// metricsBytes = nil
// }
//
// session := models.DBSession{
// Ani: sess.ANI,
// Direction: sess.Direction,
// Dnis: sess.DNIS,
// EdgeId: sess.EdgeId,
// Id: fmt.Sprintf("%s_%s", p.ParticipantId, sess.SessionId),
// MediaEndpointStats: string(mediaEndpointStatsBytes),
// MediaType: sess.MediaType,
// Metrics: string(metricsBytes),
// ParticipantId: p.ParticipantId,
// ProtocolCallId: sess.ProtocolCallId,
// Provider: sess.Provider,
// Recording: sess.Recording,
// RemoteNameDisplayable: sess.RemoteNameDisplayable,
// SessionDnis: sess.SessionDnis,
// }
// sessions = append(sessions, session)
//
// for _, seg := range sess.Segments {
//
// segmentStart, err := time.Parse(time.RFC3339, seg.SegmentStart)
// if err != nil {
// segmentStart = time.Now()
// }
//
// segmentEnd, err := time.Parse(time.RFC3339, seg.SegmentEnd)
// if err != nil {
// segmentEnd = time.Now()
// }
//
// q850ResponseCodesBytes, err := json.Marshal(seg.Q850ResponseCodes)
// if err != nil {
// q850ResponseCodesBytes = nil
// }
//
// segment := models.DBSegment{
// Id: fmt.Sprintf("%s_%s", session.Id, seg.SegmentType),
// Conference: seg.Conference,
// DisconnectType: seg.DisconnectType,
// Q850ResponseCodes: string(q850ResponseCodesBytes),
// SegmentEnd: segmentEnd,
// SegmentStart: segmentStart,
// SegmentType: seg.SegmentType,
// SessionId: sess.SessionId,
// WrapUpCode: seg.WrapUpCode,
// }
//
// segments = append(segments, segment)
// }
// }
// }
//
// return conversation, participants, sessions, segments
//}