Spaces:
Sleeping
Sleeping
File size: 3,113 Bytes
15225f7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
const API_BASE = '/api'
class ApiService {
constructor() {
this.token = null
}
setToken(token) {
this.token = token
}
async request(endpoint, options = {}) {
const headers = {
'Content-Type': 'application/json',
...options.headers,
}
if (this.token) {
headers['Authorization'] = `Bearer ${this.token}`
}
const response = await fetch(`${API_BASE}${endpoint}`, {
...options,
headers,
})
if (!response.ok) {
const error = await response.json().catch(() => ({ detail: 'Request failed' }))
throw new Error(error.detail || 'Request failed')
}
return response.json()
}
// Grid endpoints
async getGrid(system = 'case33bw') {
return this.request(`/grid?system=${system}`)
}
async getBaseline(system = 'case33bw') {
return this.request(`/baseline/${system}`)
}
// Optimization
async optimize(data) {
return this.request('/optimize', {
method: 'POST',
body: JSON.stringify(data),
})
}
// Simulation
async simulate(data) {
return this.request('/simulate', {
method: 'POST',
body: JSON.stringify(data),
})
}
async toggleSwitch(data) {
return this.request('/simulate/toggle', {
method: 'POST',
body: JSON.stringify(data),
})
}
// Grid - Set Out of Service Lines
async setOutOfServiceLines(data) {
return this.request('/grid/set-out-of-service', {
method: 'POST',
body: JSON.stringify(data),
})
}
// Digital Twin
async digitalTwin(data) {
return this.request('/digital-twin', {
method: 'POST',
body: JSON.stringify(data),
})
}
async getScenarios(system = 'case33bw') {
return this.request(`/digital-twin/scenarios?system=${system}`)
}
// Usage & Stats
async getUsage(limit = 100) {
return this.request(`/usage?limit=${limit}`)
}
async getUsageStats() {
return this.request('/usage/stats')
}
async getUsageSummary() {
return this.request('/usage/summary')
}
// Audit
async getAuditLogs(limit = 100) {
return this.request(`/audit?limit=${limit}`)
}
async getAuditSummary() {
return this.request('/audit/summary')
}
// ROI
async calculateROI(data) {
return this.request('/roi', {
method: 'POST',
body: JSON.stringify(data),
})
}
async getPricing() {
return this.request('/roi/pricing')
}
async compareROI(numberOfFeeders) {
return this.request(`/roi/comparison?number_of_feeders=${numberOfFeeders}`)
}
// Reports
async getReportData(system = 'case33bw', method = 'hybrid') {
return this.request(`/report/data?system=${system}&method=${method}`)
}
async generateReport(data) {
const headers = {
'Content-Type': 'application/json',
}
if (this.token) {
headers['Authorization'] = `Bearer ${this.token}`
}
const response = await fetch(`${API_BASE}/report`, {
method: 'POST',
headers,
body: JSON.stringify(data),
})
return response.text()
}
}
export const api = new ApiService()
export default api
|