Skip to content

Commit a1b22f3

Browse files
authored
feat: Add support for new report schemas (#125)
1 parent 44b7647 commit a1b22f3

File tree

2 files changed

+262
-0
lines changed

2 files changed

+262
-0
lines changed

crowdin/model/reports.go

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,22 @@ const (
5454
ReportTopMembers ReportName = "top-members"
5555
ReportTranslatorAccuracy ReportName = "translator-accuracy"
5656
ReportPreTranslateAccuracy ReportName = "pre-translate-accuracy"
57+
ReportSourceContentUpdates ReportName = "source-content-updates"
58+
ReportProjectMembers ReportName = "project-members"
59+
ReportEditorIssues ReportName = "editor-issues"
60+
ReportQACheckIssues ReportName = "qa-check-issues"
61+
ReportSavingActivity ReportName = "saving-activity"
62+
ReportTranslationActivity ReportName = "translation-activity"
5763

5864
// Deprecated: Use ReportPreTranslateAccuracy instead.
5965
ReportPreTranslateEfficiency ReportName = "pre-translate-efficiency"
6066

6167
// Organization reports.
6268
ReportGroupTranslationCostsPostEditing ReportName = "group-translation-costs-pe"
6369
ReportGroupTopMembers ReportName = "group-top-members"
70+
ReportGroupTaskUsage ReportName = "group-task-usage"
71+
ReportGroupQACheckIssues ReportName = "group-qa-check-issues"
72+
ReportGroupTranslationActivity ReportName = "group-translation-activity"
6473
)
6574

6675
// ReportArchive represents a report archive.
@@ -208,6 +217,12 @@ type ReportGenerateRequest struct {
208217
// - TranslatorAccuracySchema
209218
// - PreTranslateAccuracySchema
210219
// - PreTranslateEfficiencySchema (Deprecated)
220+
// - SourceContentUpdatesSchema
221+
// - ProjectMembersSchema
222+
// - EditorIssuesSchema
223+
// - QACheckIssuesSchema
224+
// - SavingActivitySchema
225+
// - TranslationActivitySchema
211226
Schema ReportSchema `json:"schema"`
212227
}
213228

@@ -431,6 +446,80 @@ type (
431446
// Report date to in UTC, ISO 8601.
432447
DateTo string `json:"dateTo,omitempty"`
433448
}
449+
450+
// SourceContentUpdatesSchema defines the schema for the source content updates report.
451+
SourceContentUpdatesSchema struct {
452+
// Report unit. Enum: strings, words, chars, chars_with_spaces. Default: words.
453+
Unit ReportUnit `json:"unit,omitempty"`
454+
// Export file format. Enum: xlsx, csv, json. Default: xlsx.
455+
Format ReportFormat `json:"format,omitempty"`
456+
// Report date from in UTC, ISO 8601.
457+
DateFrom string `json:"dateFrom,omitempty"`
458+
// Report date to in UTC, ISO 8601.
459+
DateTo string `json:"dateTo,omitempty"`
460+
}
461+
462+
// ProjectMembersSchema defines the schema for the project members report.
463+
ProjectMembersSchema struct {
464+
// Export file format. Enum: xlsx, csv, json. Default: xlsx.
465+
Format ReportFormat `json:"format,omitempty"`
466+
// Report date from in UTC, ISO 8601.
467+
DateFrom string `json:"dateFrom,omitempty"`
468+
// Report date to in UTC, ISO 8601.
469+
DateTo string `json:"dateTo,omitempty"`
470+
}
471+
472+
// EditorIssuesSchema defines the schema for the editor issues report.
473+
EditorIssuesSchema struct {
474+
// Report date from in UTC, ISO 8601.
475+
DateFrom string `json:"dateFrom,omitempty"`
476+
// Report date to in UTC, ISO 8601.
477+
DateTo string `json:"dateTo,omitempty"`
478+
// Export file format. Enum: xlsx, csv, json. Default: xlsx.
479+
Format ReportFormat `json:"format,omitempty"`
480+
// Issue type filter.
481+
IssueType string `json:"issueType,omitempty"`
482+
}
483+
484+
// QACheckIssuesSchema defines the schema for the QA check issues report.
485+
QACheckIssuesSchema struct {
486+
// Export file format. Enum: xlsx, csv, json. Default: xlsx.
487+
Format ReportFormat `json:"format,omitempty"`
488+
// Language Identifier for which the report should be generated.
489+
LanguageID string `json:"languageId,omitempty"`
490+
// Report date from in UTC, ISO 8601.
491+
DateFrom string `json:"dateFrom,omitempty"`
492+
// Report date to in UTC, ISO 8601.
493+
DateTo string `json:"dateTo,omitempty"`
494+
}
495+
496+
// SavingActivitySchema defines the schema for the saving activity report.
497+
SavingActivitySchema struct {
498+
// Report unit. Enum: strings, words, chars, chars_with_spaces. Default: words.
499+
Unit ReportUnit `json:"unit,omitempty"`
500+
// Language Identifier for which the report should be generated.
501+
LanguageID string `json:"languageId,omitempty"`
502+
// Export file format. Enum: xlsx, csv, json. Default: xlsx.
503+
Format ReportFormat `json:"format,omitempty"`
504+
// Report date from in UTC, ISO 8601.
505+
DateFrom string `json:"dateFrom,omitempty"`
506+
// Report date to in UTC, ISO 8601.
507+
DateTo string `json:"dateTo,omitempty"`
508+
}
509+
510+
// TranslationActivitySchema defines the schema for the translation activity report.
511+
TranslationActivitySchema struct {
512+
// Report unit. Enum: strings, words, chars, chars_with_spaces. Default: words.
513+
Unit ReportUnit `json:"unit,omitempty"`
514+
// Language Identifier for which the report should be generated.
515+
LanguageID string `json:"languageId,omitempty"`
516+
// Export file format. Enum: xlsx, csv, json. Default: xlsx.
517+
Format ReportFormat `json:"format,omitempty"`
518+
// Report date from in UTC, ISO 8601.
519+
DateFrom string `json:"dateFrom,omitempty"`
520+
// Report date to in UTC, ISO 8601.
521+
DateTo string `json:"dateTo,omitempty"`
522+
}
434523
)
435524

436525
// Validate checks if the request is valid.
@@ -495,6 +584,42 @@ func (r *PreTranslateEfficiencySchema) ValidateSchema() error {
495584
return nil
496585
}
497586

587+
// ValidateSchema implements the ReportSchema interface and checks if the
588+
// SourceContentUpdates schema is valid.
589+
func (r *SourceContentUpdatesSchema) ValidateSchema() error {
590+
return nil
591+
}
592+
593+
// ValidateSchema implements the ReportSchema interface and checks if the
594+
// ProjectMembers schema is valid.
595+
func (r *ProjectMembersSchema) ValidateSchema() error {
596+
return nil
597+
}
598+
599+
// ValidateSchema implements the ReportSchema interface and checks if the
600+
// EditorIssues schema is valid.
601+
func (r *EditorIssuesSchema) ValidateSchema() error {
602+
return nil
603+
}
604+
605+
// ValidateSchema implements the ReportSchema interface and checks if the
606+
// QACheckIssues schema is valid.
607+
func (r *QACheckIssuesSchema) ValidateSchema() error {
608+
return nil
609+
}
610+
611+
// ValidateSchema implements the ReportSchema interface and checks if the
612+
// SavingActivity schema is valid.
613+
func (r *SavingActivitySchema) ValidateSchema() error {
614+
return nil
615+
}
616+
617+
// ValidateSchema implements the ReportSchema interface and checks if the
618+
// TranslationActivity schema is valid.
619+
func (r *TranslationActivitySchema) ValidateSchema() error {
620+
return nil
621+
}
622+
498623
// GroupReportGenerateRequest defines the structure of a request to
499624
// generate a group or organization report.
500625
type GroupReportGenerateRequest struct {
@@ -504,6 +629,9 @@ type GroupReportGenerateRequest struct {
504629
// One of the following types:
505630
// - GroupTransactionCostsPostEditingSchema
506631
// - GroupTopMembersSchema
632+
// - GroupTaskUsageSchema
633+
// - GroupQACheckIssuesSchema
634+
// - GroupTranslationActivitySchema
507635
Schema ReportGroupSchema `json:"schema"`
508636
}
509637

@@ -513,6 +641,9 @@ type GroupReportGenerateRequest struct {
513641
// Schema can be one of the following types:
514642
// - GroupTransactionCostsPostEditingSchema
515643
// - GroupTopMembersSchema
644+
// - GroupTaskUsageSchema
645+
// - GroupQACheckIssuesSchema
646+
// - GroupTranslationActivitySchema
516647
type ReportGroupSchema interface {
517648
ValidateGroupSchema() error
518649
}
@@ -571,6 +702,56 @@ type (
571702
// Report date to in UTC, ISO 8601.
572703
DateTo string `json:"dateTo,omitempty"`
573704
}
705+
706+
// GroupTaskUsageSchema defines the schema for the group task usage report.
707+
GroupTaskUsageSchema struct {
708+
// Export file format. Enum: xlsx, csv, json. Default: xlsx.
709+
Format ReportFormat `json:"format,omitempty"`
710+
// Report type filter.
711+
Type string `json:"type,omitempty"`
712+
// Project identifiers for which the report should be generated.
713+
ProjectIDs []int `json:"projectIds,omitempty"`
714+
// Report date from in UTC, ISO 8601.
715+
DateFrom string `json:"dateFrom,omitempty"`
716+
// Report date to in UTC, ISO 8601.
717+
DateTo string `json:"dateTo,omitempty"`
718+
// Group results by the specified attribute.
719+
GroupBy string `json:"groupBy,omitempty"`
720+
// Task type identifier filter.
721+
TypeTasks int `json:"typeTasks,omitempty"`
722+
// Language Identifier for which the report should be generated.
723+
LanguageID string `json:"languageId,omitempty"`
724+
// Task creator identifier filter.
725+
CreatorID int `json:"creatorId,omitempty"`
726+
// Task assignee identifier filter.
727+
AssigneeID int `json:"assigneeId,omitempty"`
728+
}
729+
730+
// GroupQACheckIssuesSchema defines the schema for the group QA check issues report.
731+
GroupQACheckIssuesSchema struct {
732+
// Project identifiers for which the report should be generated.
733+
ProjectIDs []int `json:"projectIds,omitempty"`
734+
// Export file format. Enum: xlsx, csv, json. Default: xlsx.
735+
Format ReportFormat `json:"format,omitempty"`
736+
// Report date from in UTC, ISO 8601.
737+
DateFrom string `json:"dateFrom,omitempty"`
738+
// Report date to in UTC, ISO 8601.
739+
DateTo string `json:"dateTo,omitempty"`
740+
}
741+
742+
// GroupTranslationActivitySchema defines the schema for the group translation activity report.
743+
GroupTranslationActivitySchema struct {
744+
// Project identifiers for which the report should be generated.
745+
ProjectIDs []int `json:"projectIds,omitempty"`
746+
// Report unit. Enum: strings, words, chars, chars_with_spaces. Default: words.
747+
Unit ReportUnit `json:"unit,omitempty"`
748+
// Export file format. Enum: xlsx, csv, json. Default: xlsx.
749+
Format ReportFormat `json:"format,omitempty"`
750+
// Report date from in UTC, ISO 8601.
751+
DateFrom string `json:"dateFrom,omitempty"`
752+
// Report date to in UTC, ISO 8601.
753+
DateTo string `json:"dateTo,omitempty"`
754+
}
574755
)
575756

576757
// Validate checks if the request is valid.
@@ -609,6 +790,21 @@ func (r *GroupTopMembersSchema) ValidateGroupSchema() error {
609790
return nil
610791
}
611792

793+
// ValidateGroupSchema checks if the GroupTaskUsage schema is valid.
794+
func (r *GroupTaskUsageSchema) ValidateGroupSchema() error {
795+
return nil
796+
}
797+
798+
// ValidateGroupSchema checks if the GroupQACheckIssues schema is valid.
799+
func (r *GroupQACheckIssuesSchema) ValidateGroupSchema() error {
800+
return nil
801+
}
802+
803+
// ValidateGroupSchema checks if the GroupTranslationActivity schema is valid.
804+
func (r *GroupTranslationActivitySchema) ValidateGroupSchema() error {
805+
return nil
806+
}
807+
612808
// ReportSettingsTemplate represents a report settings template.
613809
type ReportSettingsTemplate struct {
614810
ID int `json:"id"`

crowdin/model/reports_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,54 @@ func TestReportGenerateRequestValidate(t *testing.T) {
9999
},
100100
valid: true,
101101
},
102+
{
103+
name: "valid schema (ReportSourceContentUpdates)",
104+
req: &ReportGenerateRequest{
105+
Name: ReportSourceContentUpdates,
106+
Schema: &SourceContentUpdatesSchema{Unit: ReportUnitWords},
107+
},
108+
valid: true,
109+
},
110+
{
111+
name: "valid schema (ReportProjectMembers)",
112+
req: &ReportGenerateRequest{
113+
Name: ReportProjectMembers,
114+
Schema: &ProjectMembersSchema{Format: ReportFormatXLSX},
115+
},
116+
valid: true,
117+
},
118+
{
119+
name: "valid schema (ReportEditorIssues)",
120+
req: &ReportGenerateRequest{
121+
Name: ReportEditorIssues,
122+
Schema: &EditorIssuesSchema{IssueType: "general_question"},
123+
},
124+
valid: true,
125+
},
126+
{
127+
name: "valid schema (ReportQACheckIssues)",
128+
req: &ReportGenerateRequest{
129+
Name: ReportQACheckIssues,
130+
Schema: &QACheckIssuesSchema{LanguageID: "ach"},
131+
},
132+
valid: true,
133+
},
134+
{
135+
name: "valid schema (ReportSavingActivity)",
136+
req: &ReportGenerateRequest{
137+
Name: ReportSavingActivity,
138+
Schema: &SavingActivitySchema{LanguageID: "ach", Unit: ReportUnitWords},
139+
},
140+
valid: true,
141+
},
142+
{
143+
name: "valid schema (ReportTranslationActivity)",
144+
req: &ReportGenerateRequest{
145+
Name: ReportTranslationActivity,
146+
Schema: &TranslationActivitySchema{LanguageID: "ach", Unit: ReportUnitWords},
147+
},
148+
valid: true,
149+
},
102150
{
103151
name: "valid schema (TranslatorAccuracySchema)",
104152
req: &ReportGenerateRequest{
@@ -201,6 +249,24 @@ func TestGroupReportGenerateRequestValidate(t *testing.T) {
201249
Schema: &GroupTopMembersSchema{ProjectIDs: []int{1, 2}, Unit: ReportUnitWords, LanguageID: "uk"}},
202250
valid: true,
203251
},
252+
{
253+
name: "valid request (GroupTaskUsageSchema)",
254+
req: &GroupReportGenerateRequest{Name: ReportGroupTaskUsage,
255+
Schema: &GroupTaskUsageSchema{ProjectIDs: []int{1}, Type: "workload"}},
256+
valid: true,
257+
},
258+
{
259+
name: "valid request (GroupQACheckIssuesSchema)",
260+
req: &GroupReportGenerateRequest{Name: ReportGroupQACheckIssues,
261+
Schema: &GroupQACheckIssuesSchema{ProjectIDs: []int{1, 2}, Format: ReportFormatXLSX}},
262+
valid: true,
263+
},
264+
{
265+
name: "valid request (GroupTranslationActivitySchema)",
266+
req: &GroupReportGenerateRequest{Name: ReportGroupTranslationActivity,
267+
Schema: &GroupTranslationActivitySchema{ProjectIDs: []int{1}, Unit: ReportUnitWords}},
268+
valid: true,
269+
},
204270
}
205271

206272
for _, tt := range tests {

0 commit comments

Comments
 (0)