@umituz/react-native-ai-generation-content 1.90.2 → 1.90.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/domain/interfaces/app-services-auth.interface.ts +27 -0
- package/src/domain/interfaces/app-services-composite.interface.ts +29 -0
- package/src/domain/interfaces/app-services-optional.interface.ts +42 -0
- package/src/domain/interfaces/app-services.interface.ts +0 -79
- package/src/domain/interfaces/index.ts +3 -0
- package/src/domains/background/infrastructure/services/job-poller-index.ts +7 -0
- package/src/domains/background/infrastructure/services/job-poller-utils.ts +127 -0
- package/src/domains/background/infrastructure/services/job-poller.service.ts +85 -140
- package/src/domains/background/infrastructure/utils/polling-interval.util.ts +1 -1
- package/src/domains/background/presentation/hooks/use-background-generation.ts +1 -1
- package/src/domains/content-moderation/index.ts +7 -13
- package/src/domains/content-moderation/infrastructure/services/content-moderation.service.ts +1 -1
- package/src/domains/content-moderation/infrastructure/services/moderators/image.moderator.ts +34 -8
- package/src/domains/content-moderation/infrastructure/services/moderators/text.moderator.ts +15 -4
- package/src/domains/content-moderation/infrastructure/services/moderators/video.moderator.ts +34 -8
- package/src/domains/content-moderation/infrastructure/services/moderators/voice.moderator.ts +19 -8
- package/src/domains/content-moderation/infrastructure/services/pattern-matcher.service.ts +1 -2
- package/src/domains/creations/domain/types/creation-categories.constants.ts +57 -0
- package/src/domains/creations/domain/types/creation-categories.helpers.ts +67 -0
- package/src/domains/creations/domain/types/creation-categories.ts +7 -114
- package/src/domains/creations/domain/utils/creation-display.util.ts +1 -1
- package/src/domains/creations/domain/utils/status-helpers.ts +1 -1
- package/src/domains/creations/presentation/hooks/creation-validators.ts +31 -29
- package/src/domains/creations/presentation/hooks/job-poller-index.ts +10 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.filters.ts +34 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.logger.ts +76 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.stale-handlers.ts +52 -0
- package/src/domains/creations/presentation/hooks/job-poller-utils.ts +8 -0
- package/src/domains/creations/presentation/hooks/useCreations.ts +1 -1
- package/src/domains/creations/presentation/hooks/useProcessingJobsPoller.ts +18 -235
- package/src/domains/creations/presentation/screens/CreationsGalleryScreen.tsx +1 -2
- package/src/domains/creations/presentation-exports.ts +2 -2
- package/src/domains/face-detection/domain/entities/FaceDetection.ts +4 -3
- package/src/domains/face-detection/presentation/hooks/useFaceDetection.ts +24 -21
- package/src/domains/generation/infrastructure/appearance-analysis/index.ts +5 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-preparation.ts +58 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-prompt.ts +69 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple-resolution.ts +77 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-couple.ts +54 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-index.ts +8 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder-scenario.ts +112 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/builder.ts +7 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/index.ts +20 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/types.ts +44 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-end-logger.ts +18 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-start-logger.ts +57 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/builder-step-logger.ts +106 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/index.ts +8 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils/types.ts +49 -0
- package/src/domains/generation/infrastructure/couple-generation-builder/utils.ts +8 -0
- package/src/domains/generation/infrastructure/flow/flow-store-actions.ts +105 -0
- package/src/domains/generation/infrastructure/flow/flow-store-initial-state.ts +26 -0
- package/src/domains/generation/infrastructure/flow/useFlowStore.ts +4 -116
- package/src/domains/generation/presentation/useAIGeneration.hook.ts +1 -1
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation-strategy-index.ts +7 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.ts +2 -12
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.types.ts +11 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.executor.utils.ts +12 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-generation.strategy.ts +1 -220
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-builder.ts +66 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-extraction.ts +88 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-prompt-builder.ts +74 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-input-style-enhancements.ts +35 -0
- package/src/domains/generation/wizard/infrastructure/strategies/image-strategy-factory.ts +41 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-executor-index.ts +10 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-executor.ts +76 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-input-builder.ts +46 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-result-types.ts +17 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation-submission.ts +61 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.audio-extractor.ts +27 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.executor.ts +2 -176
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.input-builder.ts +90 -0
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.strategy.ts +3 -108
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.types.ts +0 -130
- package/src/domains/generation/wizard/infrastructure/strategies/video-generation.validation.ts +136 -0
- package/src/domains/generation/wizard/presentation/hooks/photo-upload/index.ts +40 -0
- package/src/domains/generation/wizard/presentation/hooks/photo-upload/types.ts +37 -0
- package/src/domains/generation/wizard/presentation/hooks/photo-upload/usePhotoUploadStateLogic.ts +142 -0
- package/src/domains/generation/wizard/presentation/hooks/use-video-queue-utils.ts +102 -0
- package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.handlers.ts +97 -0
- package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.saver.ts +54 -0
- package/src/domains/generation/wizard/presentation/hooks/usePhotoBlockingGeneration.ts +22 -87
- package/src/domains/generation/wizard/presentation/hooks/usePhotoUploadState.ts +8 -177
- package/src/domains/generation/wizard/presentation/hooks/useVideoQueueGeneration.ts +1 -295
- package/src/domains/generation/wizard/presentation/hooks/useWizardGeneration.ts +1 -1
- package/src/domains/generation/wizard/presentation/hooks/video-queue/index.ts +77 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/use-video-queue-utils.ts +123 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationCallbacks.ts +119 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationPolling.ts +75 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationRefs.ts +65 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue/useVideoQueueGenerationStart.ts +123 -0
- package/src/domains/generation/wizard/presentation/hooks/video-queue-index.ts +9 -0
- package/src/domains/image-to-video/domain/types/image-to-video-state.types.ts +11 -4
- package/src/domains/text-to-image/domain/constants/index.ts +5 -6
- package/src/domains/text-to-image/domain/types/text-to-image.types.ts +43 -22
- package/src/domains/text-to-video/domain/types/request.types.ts +32 -9
- package/src/domains/text-to-video/domain/types/state.types.ts +22 -22
- package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.handlers.ts +44 -0
- package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.ts +5 -51
- package/src/domains/text-to-video/presentation/hooks/useTextToVideoForm.types.ts +33 -0
- package/src/exports/features.ts +1 -1
- package/src/infrastructure/services/generation-orchestrator.service.ts +2 -2
- package/src/infrastructure/utils/couple-input-context.ts +13 -0
- package/src/infrastructure/utils/couple-input-index.ts +9 -0
- package/src/infrastructure/utils/couple-input-photorealistic.ts +40 -0
- package/src/infrastructure/utils/couple-input-refiner.ts +101 -0
- package/src/infrastructure/utils/couple-input-resolver.ts +71 -0
- package/src/infrastructure/utils/couple-input-types.ts +11 -0
- package/src/infrastructure/utils/couple-input.util.ts +3 -176
- package/src/infrastructure/utils/photo-generation/photo-preparation.util.ts +1 -1
- package/src/infrastructure/validation/base-validator.ts +3 -26
- package/src/infrastructure/validation/base-validator.types.ts +32 -0
- package/src/presentation/hooks/generation/index.ts +1 -1
- package/src/presentation/hooks/generation/orchestrator-abort-logs.ts +48 -0
- package/src/presentation/hooks/generation/orchestrator-execution-logs.ts +67 -0
- package/src/presentation/hooks/generation/orchestrator-index.ts +14 -0
- package/src/presentation/hooks/generation/orchestrator-start-logs.ts +65 -0
- package/src/presentation/hooks/generation/orchestrator-state-utils.ts +17 -0
- package/src/presentation/hooks/generation/orchestrator-types.ts +55 -0
- package/src/presentation/hooks/generation/orchestrator-utils-index.ts +29 -0
- package/src/presentation/hooks/generation/orchestrator-utils.ts +25 -0
- package/src/presentation/hooks/generation/useDualImageGeneration.ts +1 -1
- package/src/presentation/hooks/generation/useImageGeneration.ts +1 -1
- package/src/presentation/hooks/generation/useVideoGeneration.ts +1 -1
- package/src/shared/hooks/factories/generation-hook-index.ts +12 -0
- package/src/shared/hooks/factories/generation-hook-types.ts +47 -0
- package/src/shared/hooks/factories/generation-hook-utils.ts +94 -0
- package/src/shared/hooks/factories/index.ts +1 -1
- package/src/shared/index.ts +1 -1
- package/src/shared/utils/calculations/aspect-ratio-calculations.ts +30 -0
- package/src/shared/utils/calculations/base64-calculations.ts +26 -0
- package/src/shared/utils/calculations/confidence-calculations.ts +21 -0
- package/src/shared/utils/calculations/cost-calculations-index.ts +43 -0
- package/src/shared/utils/calculations/cost-calculations.ts +25 -0
- package/src/shared/utils/calculations/credit-calculations.ts +37 -0
- package/src/shared/utils/calculations/index.ts +46 -0
- package/src/shared/utils/calculations/math-utilities.ts +32 -0
- package/src/shared/utils/calculations/memory-calculations.ts +33 -0
- package/src/shared/utils/calculations/pagination-calculations.ts +38 -0
- package/src/shared/utils/calculations/percentage-calculations.ts +33 -0
- package/src/shared/utils/calculations/time-calculations.ts +99 -0
- package/src/shared/utils/credit.ts +1 -1
- package/src/shared-kernel/application/hooks/index.ts +8 -0
- package/src/shared-kernel/application/hooks/use-feature-state.ts +106 -0
- package/src/shared-kernel/application/hooks/use-generation-handler.ts +110 -0
- package/src/shared-kernel/base-types/base-callbacks.types.ts +73 -0
- package/src/shared-kernel/base-types/base-feature-state.types.ts +77 -0
- package/src/shared-kernel/base-types/base-generation.types.ts +69 -0
- package/src/shared-kernel/base-types/index.ts +30 -0
- package/src/shared-kernel/domain/base-generation-strategy.ts +146 -0
- package/src/shared-kernel/domain/index.ts +7 -0
- package/src/shared-kernel/index.ts +17 -0
- package/src/shared-kernel/infrastructure/validation/common-validators.ts +126 -0
- package/src/shared-kernel/infrastructure/validation/common-validators.types.ts +33 -0
- package/src/shared-kernel/infrastructure/validation/error-handler.ts +52 -0
- package/src/shared-kernel/infrastructure/validation/error-handler.types.ts +38 -0
- package/src/shared-kernel/infrastructure/validation/error-handler.utils.ts +79 -0
- package/src/shared-kernel/infrastructure/validation/index.ts +70 -0
- package/src/domains/content-moderation/infrastructure/services/index.ts +0 -8
- package/src/domains/creations/domain/constants/index.ts +0 -12
- package/src/domains/creations/domain/utils/index.ts +0 -12
- package/src/domains/generation/infrastructure/couple-generation-builder.ts +0 -374
- package/src/domains/image-to-video/domain/index.ts +0 -2
- package/src/domains/image-to-video/infrastructure/index.ts +0 -1
- package/src/domains/image-to-video/presentation/index.ts +0 -5
- package/src/domains/text-to-video/domain/index.ts +0 -1
- package/src/domains/text-to-video/presentation/index.ts +0 -7
- package/src/presentation/hooks/generation/orchestrator.ts +0 -276
- package/src/shared/hooks/factories/createGenerationHook.ts +0 -253
- package/src/shared/utils/calculations.util.ts +0 -366
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculation Utilities
|
|
3
|
-
* Centralized calculation operations for better performance and maintainability
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Time & Duration Calculations
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Calculate age in milliseconds from a timestamp
|
|
12
|
-
*/
|
|
13
|
-
export function calculateAgeMs(timestamp: Date | number): number {
|
|
14
|
-
const time = typeof timestamp === "number" ? timestamp : timestamp.getTime();
|
|
15
|
-
return Date.now() - time;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Calculate age in seconds from a timestamp
|
|
20
|
-
*/
|
|
21
|
-
export function calculateAgeSeconds(timestamp: Date | number): number {
|
|
22
|
-
return Math.floor(calculateAgeMs(timestamp) / 1000);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Calculate age in minutes from a timestamp
|
|
27
|
-
*/
|
|
28
|
-
export function calculateAgeMinutes(timestamp: Date | number): number {
|
|
29
|
-
return Math.floor(calculateAgeSeconds(timestamp) / 60);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Check if timestamp is older than specified milliseconds
|
|
34
|
-
*/
|
|
35
|
-
export function isOlderThan(timestamp: Date | number, maxAgeMs: number): boolean {
|
|
36
|
-
return calculateAgeMs(timestamp) > maxAgeMs;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Calculate duration between two timestamps in milliseconds
|
|
41
|
-
*/
|
|
42
|
-
export function calculateDurationMs(
|
|
43
|
-
startTime: Date | number,
|
|
44
|
-
endTime: Date | number = Date.now()
|
|
45
|
-
): number {
|
|
46
|
-
const start = typeof startTime === "number" ? startTime : startTime.getTime();
|
|
47
|
-
const end = typeof endTime === "number" ? endTime : endTime.getTime();
|
|
48
|
-
return end - start;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Format duration in milliseconds to human-readable string
|
|
53
|
-
*/
|
|
54
|
-
export function formatDuration(ms: number): string {
|
|
55
|
-
const seconds = Math.floor(ms / 1000);
|
|
56
|
-
const minutes = Math.floor(seconds / 60);
|
|
57
|
-
const hours = Math.floor(minutes / 60);
|
|
58
|
-
|
|
59
|
-
if (hours > 0) {
|
|
60
|
-
return `${hours}h ${minutes % 60}m`;
|
|
61
|
-
}
|
|
62
|
-
if (minutes > 0) {
|
|
63
|
-
return `${minutes}m ${seconds % 60}s`;
|
|
64
|
-
}
|
|
65
|
-
return `${seconds}s`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Polling Calculations
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Calculate polling interval with exponential backoff
|
|
74
|
-
*/
|
|
75
|
-
export function calculatePollingInterval(options: {
|
|
76
|
-
attempt: number;
|
|
77
|
-
initialIntervalMs: number;
|
|
78
|
-
maxIntervalMs: number;
|
|
79
|
-
backoffMultiplier: number;
|
|
80
|
-
}): number {
|
|
81
|
-
const { attempt, initialIntervalMs, maxIntervalMs, backoffMultiplier } = options;
|
|
82
|
-
|
|
83
|
-
if (attempt === 0) {
|
|
84
|
-
return 0;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const interval = initialIntervalMs * Math.pow(backoffMultiplier, attempt - 1);
|
|
88
|
-
return Math.min(interval, maxIntervalMs);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Calculate estimated total polling time
|
|
93
|
-
*/
|
|
94
|
-
export function calculateEstimatedPollingTime(options: {
|
|
95
|
-
maxAttempts: number;
|
|
96
|
-
initialIntervalMs: number;
|
|
97
|
-
maxIntervalMs: number;
|
|
98
|
-
backoffMultiplier: number;
|
|
99
|
-
}): number {
|
|
100
|
-
let total = 0;
|
|
101
|
-
for (let attempt = 1; attempt < options.maxAttempts; attempt++) {
|
|
102
|
-
total += calculatePollingInterval({ ...options, attempt });
|
|
103
|
-
if (total >= options.maxIntervalMs * options.maxAttempts) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return total;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Progress & Percentage Calculations
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Calculate percentage with bounds checking (0-100)
|
|
116
|
-
*/
|
|
117
|
-
export function calculatePercentage(value: number, total: number): number {
|
|
118
|
-
if (total === 0) return 0;
|
|
119
|
-
const percentage = (value / total) * 100;
|
|
120
|
-
return Math.max(0, Math.min(100, percentage));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Calculate progress with min/max bounds
|
|
125
|
-
*/
|
|
126
|
-
export function calculateProgress(
|
|
127
|
-
current: number,
|
|
128
|
-
total: number,
|
|
129
|
-
min: number = 0,
|
|
130
|
-
max: number = 100
|
|
131
|
-
): number {
|
|
132
|
-
if (total === 0) return min;
|
|
133
|
-
const percentage = (current / total) * (max - min) + min;
|
|
134
|
-
return Math.max(min, Math.min(max, percentage));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Calculate remaining percentage
|
|
139
|
-
*/
|
|
140
|
-
export function calculateRemaining(current: number, total: number): number {
|
|
141
|
-
return Math.max(0, total - current);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Array & Collection Calculations
|
|
146
|
-
*/
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Calculate filtered count with predicate
|
|
150
|
-
*/
|
|
151
|
-
export function calculateFilteredCount<T>(
|
|
152
|
-
items: readonly T[],
|
|
153
|
-
predicate: (item: T) => boolean
|
|
154
|
-
): number {
|
|
155
|
-
return items.reduce((count, item) => (predicate(item) ? count + 1 : count), 0);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Calculate pagination slice
|
|
160
|
-
*/
|
|
161
|
-
export function calculatePaginationSlice(
|
|
162
|
-
totalItems: number,
|
|
163
|
-
page: number,
|
|
164
|
-
pageSize: number
|
|
165
|
-
): { start: number; end: number; count: number } {
|
|
166
|
-
const start = page * pageSize;
|
|
167
|
-
const end = Math.min(start + pageSize, totalItems);
|
|
168
|
-
const count = end - start;
|
|
169
|
-
return { start, end, count };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Calculate if more items exist for pagination
|
|
174
|
-
*/
|
|
175
|
-
export function calculateHasMore(
|
|
176
|
-
currentCount: number,
|
|
177
|
-
currentPage: number,
|
|
178
|
-
pageSize: number
|
|
179
|
-
): boolean {
|
|
180
|
-
return currentCount >= currentPage * pageSize;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Base64 & Size Calculations
|
|
185
|
-
*/
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Calculate base64 size in bytes
|
|
189
|
-
*/
|
|
190
|
-
export function calculateBase64Size(base64: string): number {
|
|
191
|
-
// Remove data URI prefix if present
|
|
192
|
-
const cleanBase64 = base64.replace(/^data:[^;]+;base64,/, "");
|
|
193
|
-
return (cleanBase64.length * 3) / 4;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Calculate base64 size in megabytes
|
|
198
|
-
*/
|
|
199
|
-
export function calculateBase64SizeMB(base64: string): number {
|
|
200
|
-
return calculateBase64Size(base64) / (1024 * 1024);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Calculate if base64 size is within limit
|
|
205
|
-
*/
|
|
206
|
-
export function isBase64SizeWithinLimit(base64: string, maxSizeMB: number): boolean {
|
|
207
|
-
return calculateBase64SizeMB(base64) <= maxSizeMB;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Confidence Score Calculations
|
|
212
|
-
*/
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Calculate confidence score from violations with weights
|
|
216
|
-
*/
|
|
217
|
-
export function calculateConfidenceScore(
|
|
218
|
-
violations: readonly { severity: "critical" | "high" | "medium" | "low" }[]
|
|
219
|
-
): number {
|
|
220
|
-
if (violations.length === 0) return 1.0;
|
|
221
|
-
|
|
222
|
-
const weights = { critical: 1.0, high: 0.75, medium: 0.5, low: 0.25 };
|
|
223
|
-
const score = violations.reduce(
|
|
224
|
-
(sum, v) => sum + (weights[v.severity] || 0.25),
|
|
225
|
-
0
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
// Normalize by number of violations, capped at 1.0
|
|
229
|
-
return Math.min(1.0, score / Math.max(1, violations.length));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Credit & Cost Calculations
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Calculate cost in credits based on duration and resolution
|
|
238
|
-
*/
|
|
239
|
-
export function calculateCredits(
|
|
240
|
-
durationSeconds: number,
|
|
241
|
-
resolutionMultiplier: number = 1,
|
|
242
|
-
baseCost: number = 1
|
|
243
|
-
): number {
|
|
244
|
-
return Math.ceil((durationSeconds / 60) * resolutionMultiplier * baseCost);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Calculate resolution multiplier for credits
|
|
249
|
-
*/
|
|
250
|
-
export function calculateResolutionMultiplier(width: number, height: number): number {
|
|
251
|
-
const totalPixels = width * height;
|
|
252
|
-
const basePixels = 720 * 1280; // HD baseline
|
|
253
|
-
|
|
254
|
-
if (totalPixels <= basePixels) return 1;
|
|
255
|
-
if (totalPixels <= basePixels * 2) return 1.5;
|
|
256
|
-
if (totalPixels <= basePixels * 4) return 2;
|
|
257
|
-
return 3;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Calculate cost to credits conversion
|
|
262
|
-
*/
|
|
263
|
-
export function convertCostToCredits(
|
|
264
|
-
cost: number,
|
|
265
|
-
creditsPerDollar: number = 100
|
|
266
|
-
): number {
|
|
267
|
-
return Math.ceil(cost * creditsPerDollar);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Aspect Ratio Calculations
|
|
272
|
-
*/
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Calculate aspect ratio from dimensions
|
|
276
|
-
*/
|
|
277
|
-
export function calculateAspectRatio(width: number, height: number): number {
|
|
278
|
-
return width / height;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Calculate height from width and aspect ratio
|
|
283
|
-
*/
|
|
284
|
-
export function calculateHeightFromAspectRatio(
|
|
285
|
-
width: number,
|
|
286
|
-
aspectRatio: number
|
|
287
|
-
): number {
|
|
288
|
-
return Math.round(width / aspectRatio);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Calculate width from height and aspect ratio
|
|
293
|
-
*/
|
|
294
|
-
export function calculateWidthFromAspectRatio(
|
|
295
|
-
height: number,
|
|
296
|
-
aspectRatio: number
|
|
297
|
-
): number {
|
|
298
|
-
return Math.round(height * aspectRatio);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Memory & Performance Calculations
|
|
303
|
-
*/
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Calculate estimated memory usage for image
|
|
307
|
-
*/
|
|
308
|
-
export function calculateImageMemoryUsage(
|
|
309
|
-
width: number,
|
|
310
|
-
height: number,
|
|
311
|
-
bytesPerPixel: number = 4 // RGBA
|
|
312
|
-
): number {
|
|
313
|
-
return width * height * bytesPerPixel;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Calculate estimated memory usage in MB
|
|
318
|
-
*/
|
|
319
|
-
export function calculateMemoryMB(bytes: number): number {
|
|
320
|
-
return bytes / (1024 * 1024);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Calculate safe batch size for processing
|
|
325
|
-
*/
|
|
326
|
-
export function calculateSafeBatchSize(
|
|
327
|
-
availableMemoryMB: number,
|
|
328
|
-
itemSizeMB: number,
|
|
329
|
-
safetyFactor: number = 0.7
|
|
330
|
-
): number {
|
|
331
|
-
const safeMemory = availableMemoryMB * safetyFactor;
|
|
332
|
-
return Math.max(1, Math.floor(safeMemory / itemSizeMB));
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Utility Functions
|
|
337
|
-
*/
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Clamp value between min and max
|
|
341
|
-
*/
|
|
342
|
-
export function clamp(value: number, min: number, max: number): number {
|
|
343
|
-
return Math.max(min, Math.min(max, value));
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Linear interpolation between two values
|
|
348
|
-
*/
|
|
349
|
-
export function lerp(start: number, end: number, progress: number): number {
|
|
350
|
-
return start + (end - start) * clamp(progress, 0, 1);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Map value from one range to another
|
|
355
|
-
*/
|
|
356
|
-
export function mapRange(
|
|
357
|
-
value: number,
|
|
358
|
-
inMin: number,
|
|
359
|
-
inMax: number,
|
|
360
|
-
outMin: number,
|
|
361
|
-
outMax: number
|
|
362
|
-
): number {
|
|
363
|
-
const inRange = inMax - inMin;
|
|
364
|
-
const outRange = outMax - outMin;
|
|
365
|
-
return outMin + ((value - inMin) / inRange) * outRange;
|
|
366
|
-
}
|