|
@@ -435,6 +435,11 @@ for res in output:
|
|
|
</thead>
|
|
</thead>
|
|
|
<tbody>
|
|
<tbody>
|
|
|
<tr>
|
|
<tr>
|
|
|
|
|
+<td><code>image</code></td>
|
|
|
|
|
+<td><code>string</code> | <code>null</code></td>
|
|
|
|
|
+<td>时序异常检测结果图。图像为JPEG格式,使用Base64编码。</td>
|
|
|
|
|
+</tr>
|
|
|
|
|
+<tr>
|
|
|
<td><code>csv</code></td>
|
|
<td><code>csv</code></td>
|
|
|
<td><code>string</code></td>
|
|
<td><code>string</code></td>
|
|
|
<td>服务器可访问的CSV文件的URL或CSV文件内容的Base64编码结果。CSV文件需要使用UTF-8编码。</td>
|
|
<td>服务器可访问的CSV文件的URL或CSV文件内容的Base64编码结果。CSV文件需要使用UTF-8编码。</td>
|
|
@@ -463,7 +468,8 @@ for res in output:
|
|
|
</table>
|
|
</table>
|
|
|
<p><code>result</code>示例如下:</p>
|
|
<p><code>result</code>示例如下:</p>
|
|
|
<pre><code class="language-json">{
|
|
<pre><code class="language-json">{
|
|
|
-"csv": "xxxxxx"
|
|
|
|
|
|
|
+"csv": "xxxxxx",
|
|
|
|
|
+"image": "xxxxxx"
|
|
|
}
|
|
}
|
|
|
</code></pre></details>
|
|
</code></pre></details>
|
|
|
|
|
|
|
@@ -476,42 +482,47 @@ for res in output:
|
|
|
<pre><code class="language-python">import base64
|
|
<pre><code class="language-python">import base64
|
|
|
import requests
|
|
import requests
|
|
|
|
|
|
|
|
-API_URL = "http://localhost:8080/time-series-anomaly-detection" # 服务URL
|
|
|
|
|
-csv_path = "./test.csv"
|
|
|
|
|
-output_csv_path = "./out.csv"
|
|
|
|
|
|
|
+API_URL = "http://localhost:8080/time-series-anomaly-detection" # 服务URL
|
|
|
|
|
+csv_path = "./test.csv"
|
|
|
|
|
+output_image_path = "./out.jpg"
|
|
|
|
|
+output_csv_path = "./out.csv"
|
|
|
|
|
|
|
|
-# 对本地图像进行Base64编码
|
|
|
|
|
-with open(csv_path, "rb") as file:
|
|
|
|
|
|
|
+# 对本地CSV文件进行Base64编码
|
|
|
|
|
+with open(csv_path, "rb") as file:
|
|
|
csv_bytes = file.read()
|
|
csv_bytes = file.read()
|
|
|
- csv_data = base64.b64encode(csv_bytes).decode("ascii")
|
|
|
|
|
|
|
+ csv_data = base64.b64encode(csv_bytes).decode("ascii")
|
|
|
|
|
|
|
|
-payload = {"csv": csv_data}
|
|
|
|
|
|
|
+payload = {"csv": csv_data}
|
|
|
|
|
|
|
|
# 调用API
|
|
# 调用API
|
|
|
response = requests.post(API_URL, json=payload)
|
|
response = requests.post(API_URL, json=payload)
|
|
|
|
|
|
|
|
# 处理接口返回数据
|
|
# 处理接口返回数据
|
|
|
assert response.status_code == 200
|
|
assert response.status_code == 200
|
|
|
-result = response.json()["result"]
|
|
|
|
|
-with open(output_csv_path, "wb") as f:
|
|
|
|
|
- f.write(base64.b64decode(result["csv"]))
|
|
|
|
|
-print(f"Output time-series data saved at {output_csv_path}")
|
|
|
|
|
|
|
+result = response.json()["result"]
|
|
|
|
|
+with open(output_image_path, "wb") as f:
|
|
|
|
|
+ f.write(base64.b64decode(result["image"]))
|
|
|
|
|
+print(f"Output image saved at {output_image_path}")
|
|
|
|
|
+with open(output_csv_path, "wb") as f:
|
|
|
|
|
+ f.write(base64.b64decode(result["csv"]))
|
|
|
|
|
+print(f"Output time-series data saved at {output_csv_path}")
|
|
|
</code></pre></details>
|
|
</code></pre></details>
|
|
|
|
|
|
|
|
<details><summary>C++</summary>
|
|
<details><summary>C++</summary>
|
|
|
|
|
|
|
|
<pre><code class="language-cpp">#include <iostream>
|
|
<pre><code class="language-cpp">#include <iostream>
|
|
|
-#include "cpp-httplib/httplib.h" // https://github.com/Huiyicc/cpp-httplib
|
|
|
|
|
-#include "nlohmann/json.hpp" // https://github.com/nlohmann/json
|
|
|
|
|
-#include "base64.hpp" // https://github.com/tobiaslocker/base64
|
|
|
|
|
|
|
+#include "cpp-httplib/httplib.h" // https://github.com/Huiyicc/cpp-httplib
|
|
|
|
|
+#include "nlohmann/json.hpp" // https://github.com/nlohmann/json
|
|
|
|
|
+#include "base64.hpp" // https://github.com/tobiaslocker/base64
|
|
|
|
|
|
|
|
int main() {
|
|
int main() {
|
|
|
- httplib::Client client("localhost:8080");
|
|
|
|
|
- const std::string csvPath = "./test.csv";
|
|
|
|
|
- const std::string outputCsvPath = "./out.csv";
|
|
|
|
|
|
|
+ httplib::Client client("localhost:8080");
|
|
|
|
|
+ const std::string csvPath = "./test.csv";
|
|
|
|
|
+ const std::string outputImagePath = "./out.jpg";
|
|
|
|
|
+ const std::string outputCsvPath = "./out.csv";
|
|
|
|
|
|
|
|
httplib::Headers headers = {
|
|
httplib::Headers headers = {
|
|
|
- {"Content-Type", "application/json"}
|
|
|
|
|
|
|
+ {"Content-Type", "application/json"}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 进行Base64编码
|
|
// 进行Base64编码
|
|
@@ -521,37 +532,49 @@ int main() {
|
|
|
|
|
|
|
|
std::vector<char> buffer(size);
|
|
std::vector<char> buffer(size);
|
|
|
if (!file.read(buffer.data(), size)) {
|
|
if (!file.read(buffer.data(), size)) {
|
|
|
- std::cerr << "Error reading file." << std::endl;
|
|
|
|
|
|
|
+ std::cerr << "Error reading file." << std::endl;
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
std::string bufferStr(reinterpret_cast<const char*>(buffer.data()), buffer.size());
|
|
std::string bufferStr(reinterpret_cast<const char*>(buffer.data()), buffer.size());
|
|
|
std::string encodedCsv = base64::to_base64(bufferStr);
|
|
std::string encodedCsv = base64::to_base64(bufferStr);
|
|
|
|
|
|
|
|
nlohmann::json jsonObj;
|
|
nlohmann::json jsonObj;
|
|
|
- jsonObj["csv"] = encodedCsv;
|
|
|
|
|
|
|
+ jsonObj["csv"] = encodedCsv;
|
|
|
std::string body = jsonObj.dump();
|
|
std::string body = jsonObj.dump();
|
|
|
|
|
|
|
|
// 调用API
|
|
// 调用API
|
|
|
- auto response = client.Post("/time-series-anomaly-detection", headers, body, "application/json");
|
|
|
|
|
|
|
+ auto response = client.Post("/time-series-anomaly-detection", headers, body, "application/json");
|
|
|
// 处理接口返回数据
|
|
// 处理接口返回数据
|
|
|
if (response && response->status == 200) {
|
|
if (response && response->status == 200) {
|
|
|
nlohmann::json jsonResponse = nlohmann::json::parse(response->body);
|
|
nlohmann::json jsonResponse = nlohmann::json::parse(response->body);
|
|
|
- auto result = jsonResponse["result"];
|
|
|
|
|
|
|
+ auto result = jsonResponse["result"];
|
|
|
|
|
|
|
|
// 保存数据
|
|
// 保存数据
|
|
|
- encodedCsv = result["csv"];
|
|
|
|
|
|
|
+ std::string encodedImage = result["image"];
|
|
|
|
|
+ std::string decodedString = base64::from_base64(encodedImage);
|
|
|
|
|
+ std::vector<unsigned char> decodedImage(decodedString.begin(), decodedString.end());
|
|
|
|
|
+ std::ofstream outputImage(outputImagePath, std::ios::binary | std::ios::out);
|
|
|
|
|
+ if (outputImage.is_open()) {
|
|
|
|
|
+ outputImage.write(reinterpret_cast<char*>(decodedImage.data()), decodedImage.size());
|
|
|
|
|
+ outputImage.close();
|
|
|
|
|
+ std::cout << "Output image data saved at " << outputImagePath << std::endl;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ std::cerr << "Unable to open file for writing: " << outputImagePath << std::endl;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ encodedCsv = result["csv"];
|
|
|
decodedString = base64::from_base64(encodedCsv);
|
|
decodedString = base64::from_base64(encodedCsv);
|
|
|
std::vector<unsigned char> decodedCsv(decodedString.begin(), decodedString.end());
|
|
std::vector<unsigned char> decodedCsv(decodedString.begin(), decodedString.end());
|
|
|
std::ofstream outputCsv(outputCsvPath, std::ios::binary | std::ios::out);
|
|
std::ofstream outputCsv(outputCsvPath, std::ios::binary | std::ios::out);
|
|
|
if (outputCsv.is_open()) {
|
|
if (outputCsv.is_open()) {
|
|
|
outputCsv.write(reinterpret_cast<char*>(decodedCsv.data()), decodedCsv.size());
|
|
outputCsv.write(reinterpret_cast<char*>(decodedCsv.data()), decodedCsv.size());
|
|
|
outputCsv.close();
|
|
outputCsv.close();
|
|
|
- std::cout << "Output time-series data saved at " << outputCsvPath << std::endl;
|
|
|
|
|
|
|
+ std::cout << "Output time-series data saved at " << outputCsvPath << std::endl;
|
|
|
} else {
|
|
} else {
|
|
|
- std::cerr << "Unable to open file for writing: " << outputCsvPath << std::endl;
|
|
|
|
|
|
|
+ std::cerr << "Unable to open file for writing: " << outputCsvPath << std::endl;
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- std::cout << "Failed to send HTTP request." << std::endl;
|
|
|
|
|
|
|
+ std::cout << "Failed to send HTTP request." << std::endl;
|
|
|
std::cout << response->body << std::endl;
|
|
std::cout << response->body << std::endl;
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
@@ -574,9 +597,10 @@ import java.util.Base64;
|
|
|
|
|
|
|
|
public class Main {
|
|
public class Main {
|
|
|
public static void main(String[] args) throws IOException {
|
|
public static void main(String[] args) throws IOException {
|
|
|
- String API_URL = "http://localhost:8080/time-series-anomaly-detection";
|
|
|
|
|
- String csvPath = "./test.csv";
|
|
|
|
|
- String outputCsvPath = "./out.csv";
|
|
|
|
|
|
|
+ String API_URL = "http://localhost:8080/time-series-anomaly-detection";
|
|
|
|
|
+ String csvPath = "./test.csv";
|
|
|
|
|
+ String outputImagePath = "./out.jpg";
|
|
|
|
|
+ String outputCsvPath = "./out.csv";
|
|
|
|
|
|
|
|
// 对本地csv进行Base64编码
|
|
// 对本地csv进行Base64编码
|
|
|
File file = new File(csvPath);
|
|
File file = new File(csvPath);
|
|
@@ -585,11 +609,11 @@ public class Main {
|
|
|
|
|
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
ObjectNode params = objectMapper.createObjectNode();
|
|
ObjectNode params = objectMapper.createObjectNode();
|
|
|
- params.put("csv", csvData);
|
|
|
|
|
|
|
+ params.put("csv", csvData);
|
|
|
|
|
|
|
|
// 创建 OkHttpClient 实例
|
|
// 创建 OkHttpClient 实例
|
|
|
OkHttpClient client = new OkHttpClient();
|
|
OkHttpClient client = new OkHttpClient();
|
|
|
- MediaType JSON = MediaType.Companion.get("application/json; charset=utf-8");
|
|
|
|
|
|
|
+ MediaType JSON = MediaType.Companion.get("application/json; charset=utf-8");
|
|
|
RequestBody body = RequestBody.Companion.create(params.toString(), JSON);
|
|
RequestBody body = RequestBody.Companion.create(params.toString(), JSON);
|
|
|
Request request = new Request.Builder()
|
|
Request request = new Request.Builder()
|
|
|
.url(API_URL)
|
|
.url(API_URL)
|
|
@@ -601,17 +625,24 @@ public class Main {
|
|
|
if (response.isSuccessful()) {
|
|
if (response.isSuccessful()) {
|
|
|
String responseBody = response.body().string();
|
|
String responseBody = response.body().string();
|
|
|
JsonNode resultNode = objectMapper.readTree(responseBody);
|
|
JsonNode resultNode = objectMapper.readTree(responseBody);
|
|
|
- JsonNode result = resultNode.get("result");
|
|
|
|
|
|
|
+ JsonNode result = resultNode.get("result");
|
|
|
|
|
|
|
|
// 保存返回的数据
|
|
// 保存返回的数据
|
|
|
- String base64Csv = result.get("csv").asText();
|
|
|
|
|
|
|
+ String base64Image = result.get("image").asText();
|
|
|
|
|
+ byte[] imageBytes = Base64.getDecoder().decode(base64Image);
|
|
|
|
|
+ try (FileOutputStream fos = new FileOutputStream(outputImagePath)) {
|
|
|
|
|
+ fos.write(imageBytes);
|
|
|
|
|
+ }
|
|
|
|
|
+ System.out.println("Output image data saved at " + outputImagePath);
|
|
|
|
|
+
|
|
|
|
|
+ String base64Csv = result.get("csv").asText();
|
|
|
byte[] csvBytes = Base64.getDecoder().decode(base64Csv);
|
|
byte[] csvBytes = Base64.getDecoder().decode(base64Csv);
|
|
|
try (FileOutputStream fos = new FileOutputStream(outputCsvPath)) {
|
|
try (FileOutputStream fos = new FileOutputStream(outputCsvPath)) {
|
|
|
fos.write(csvBytes);
|
|
fos.write(csvBytes);
|
|
|
}
|
|
}
|
|
|
- System.out.println("Output time-series data saved at " + outputCsvPath);
|
|
|
|
|
|
|
+ System.out.println("Output time-series data saved at " + outputCsvPath);
|
|
|
} else {
|
|
} else {
|
|
|
- System.err.println("Request failed with code: " + response.code());
|
|
|
|
|
|
|
+ System.err.println("Request failed with code: " + response.code());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -623,45 +654,46 @@ public class Main {
|
|
|
<pre><code class="language-go">package main
|
|
<pre><code class="language-go">package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
- "bytes"
|
|
|
|
|
- "encoding/base64"
|
|
|
|
|
- "encoding/json"
|
|
|
|
|
- "fmt"
|
|
|
|
|
- "io/ioutil"
|
|
|
|
|
- "net/http"
|
|
|
|
|
|
|
+ "bytes"
|
|
|
|
|
+ "encoding/base64"
|
|
|
|
|
+ "encoding/json"
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+ "io/ioutil"
|
|
|
|
|
+ "net/http"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
func main() {
|
|
|
- API_URL := "http://localhost:8080/time-series-anomaly-detection"
|
|
|
|
|
- csvPath := "./test.csv";
|
|
|
|
|
- outputCsvPath := "./out.csv";
|
|
|
|
|
|
|
+ API_URL := "http://localhost:8080/time-series-anomaly-detection"
|
|
|
|
|
+ csvPath := "./test.csv";
|
|
|
|
|
+ outputImagePath := "./out.jpg";
|
|
|
|
|
+ outputCsvPath := "./out.csv";
|
|
|
|
|
|
|
|
// 读取csv文件并进行Base64编码
|
|
// 读取csv文件并进行Base64编码
|
|
|
csvBytes, err := ioutil.ReadFile(csvPath)
|
|
csvBytes, err := ioutil.ReadFile(csvPath)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- fmt.Println("Error reading csv file:", err)
|
|
|
|
|
|
|
+ fmt.Println("Error reading csv file:", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
csvData := base64.StdEncoding.EncodeToString(csvBytes)
|
|
csvData := base64.StdEncoding.EncodeToString(csvBytes)
|
|
|
|
|
|
|
|
- payload := map[string]string{"csv": csvData} // Base64编码的文件内容
|
|
|
|
|
|
|
+ payload := map[string]string{"csv": csvData} // Base64编码的文件内容
|
|
|
payloadBytes, err := json.Marshal(payload)
|
|
payloadBytes, err := json.Marshal(payload)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- fmt.Println("Error marshaling payload:", err)
|
|
|
|
|
|
|
+ fmt.Println("Error marshaling payload:", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 调用API
|
|
// 调用API
|
|
|
client := &http.Client{}
|
|
client := &http.Client{}
|
|
|
- req, err := http.NewRequest("POST", API_URL, bytes.NewBuffer(payloadBytes))
|
|
|
|
|
|
|
+ req, err := http.NewRequest("POST", API_URL, bytes.NewBuffer(payloadBytes))
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- fmt.Println("Error creating request:", err)
|
|
|
|
|
|
|
+ fmt.Println("Error creating request:", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
res, err := client.Do(req)
|
|
res, err := client.Do(req)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- fmt.Println("Error sending request:", err)
|
|
|
|
|
|
|
+ fmt.Println("Error sending request:", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
defer res.Body.Close()
|
|
defer res.Body.Close()
|
|
@@ -669,33 +701,47 @@ func main() {
|
|
|
// 处理返回数据
|
|
// 处理返回数据
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- fmt.Println("Error reading response body:", err)
|
|
|
|
|
|
|
+ fmt.Println("Error reading response body:", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
type Response struct {
|
|
type Response struct {
|
|
|
Result struct {
|
|
Result struct {
|
|
|
- Csv string `json:"csv"`
|
|
|
|
|
- } `json:"result"`
|
|
|
|
|
|
|
+ Csv string `json:"csv"`
|
|
|
|
|
+ Image string `json:"image"`
|
|
|
|
|
+ } `json:"result"`
|
|
|
}
|
|
}
|
|
|
var respData Response
|
|
var respData Response
|
|
|
err = json.Unmarshal([]byte(string(body)), &respData)
|
|
err = json.Unmarshal([]byte(string(body)), &respData)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- fmt.Println("Error unmarshaling response body:", err)
|
|
|
|
|
|
|
+ fmt.Println("Error unmarshaling response body:", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 将Base64编码的图片数据解码并保存为文件
|
|
|
|
|
+ outputImageData, err := base64.StdEncoding.DecodeString(respData.Result.Image)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Println("Error decoding Base64 image data:", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ err = ioutil.WriteFile(outputImagePath, outputImageData, 0644)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Println("Error writing image to file:", err)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ fmt.Printf("Output image data saved at %s.jpg", outputImagePath)
|
|
|
|
|
+
|
|
|
// 将Base64编码的csv数据解码并保存为文件
|
|
// 将Base64编码的csv数据解码并保存为文件
|
|
|
outputCsvData, err := base64.StdEncoding.DecodeString(respData.Result.Csv)
|
|
outputCsvData, err := base64.StdEncoding.DecodeString(respData.Result.Csv)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- fmt.Println("Error decoding base64 csv data:", err)
|
|
|
|
|
|
|
+ fmt.Println("Error decoding base64 csv data:", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
err = ioutil.WriteFile(outputCsvPath, outputCsvData, 0644)
|
|
err = ioutil.WriteFile(outputCsvPath, outputCsvData, 0644)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- fmt.Println("Error writing csv to file:", err)
|
|
|
|
|
|
|
+ fmt.Println("Error writing csv to file:", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- fmt.Printf("Output time-series data saved at %s.csv", outputCsvPath)
|
|
|
|
|
|
|
+ fmt.Printf("Output time-series data saved at %s.csv", outputCsvPath)
|
|
|
}
|
|
}
|
|
|
</code></pre></details>
|
|
</code></pre></details>
|
|
|
|
|
|
|
@@ -711,9 +757,10 @@ using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
class Program
|
|
class Program
|
|
|
{
|
|
{
|
|
|
- static readonly string API_URL = "http://localhost:8080/time-series-anomaly-detection";
|
|
|
|
|
- static readonly string csvPath = "./test.csv";
|
|
|
|
|
- static readonly string outputCsvPath = "./out.csv";
|
|
|
|
|
|
|
+ static readonly string API_URL = "http://localhost:8080/time-series-anomaly-detection";
|
|
|
|
|
+ static readonly string csvPath = "./test.csv";
|
|
|
|
|
+ static readonly string outputImagePath = "./out.jpg";
|
|
|
|
|
+ static readonly string outputCsvPath = "./out.csv";
|
|
|
|
|
|
|
|
static async Task Main(string[] args)
|
|
static async Task Main(string[] args)
|
|
|
{
|
|
{
|
|
@@ -723,8 +770,8 @@ class Program
|
|
|
byte[] csvBytes = File.ReadAllBytes(csvPath);
|
|
byte[] csvBytes = File.ReadAllBytes(csvPath);
|
|
|
string csvData = Convert.ToBase64String(csvBytes);
|
|
string csvData = Convert.ToBase64String(csvBytes);
|
|
|
|
|
|
|
|
- var payload = new JObject{ { "csv", csvData } }; // Base64编码的文件内容
|
|
|
|
|
- var content = new StringContent(payload.ToString(), Encoding.UTF8, "application/json");
|
|
|
|
|
|
|
+ var payload = new JObject{ { "csv", csvData } }; // Base64编码的文件内容
|
|
|
|
|
+ var content = new StringContent(payload.ToString(), Encoding.UTF8, "application/json");
|
|
|
|
|
|
|
|
// 调用API
|
|
// 调用API
|
|
|
HttpResponseMessage response = await httpClient.PostAsync(API_URL, content);
|
|
HttpResponseMessage response = await httpClient.PostAsync(API_URL, content);
|
|
@@ -734,11 +781,17 @@ class Program
|
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
string responseBody = await response.Content.ReadAsStringAsync();
|
|
|
JObject jsonResponse = JObject.Parse(responseBody);
|
|
JObject jsonResponse = JObject.Parse(responseBody);
|
|
|
|
|
|
|
|
|
|
+ // 保存图片文件
|
|
|
|
|
+ string base64Image = jsonResponse["result"]["image"].ToString();
|
|
|
|
|
+ byte[] outputImageBytes = Convert.FromBase64String(base64Image);
|
|
|
|
|
+ File.WriteAllBytes(outputImagePath, outputImageBytes);
|
|
|
|
|
+ Console.WriteLine($"Output image data saved at {outputImagePath}");
|
|
|
|
|
+
|
|
|
// 保存csv文件
|
|
// 保存csv文件
|
|
|
- string base64Csv = jsonResponse["result"]["csv"].ToString();
|
|
|
|
|
|
|
+ string base64Csv = jsonResponse["result"]["csv"].ToString();
|
|
|
byte[] outputCsvBytes = Convert.FromBase64String(base64Csv);
|
|
byte[] outputCsvBytes = Convert.FromBase64String(base64Csv);
|
|
|
File.WriteAllBytes(outputCsvPath, outputCsvBytes);
|
|
File.WriteAllBytes(outputCsvPath, outputCsvBytes);
|
|
|
- Console.WriteLine($"Output time-series data saved at {outputCsvPath}");
|
|
|
|
|
|
|
+ Console.WriteLine($"Output time-series data saved at {outputCsvPath}");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
</code></pre></details>
|
|
</code></pre></details>
|
|
@@ -749,8 +802,9 @@ class Program
|
|
|
const fs = require('fs');
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
const API_URL = 'http://localhost:8080/time-series-anomaly-detection'
|
|
const API_URL = 'http://localhost:8080/time-series-anomaly-detection'
|
|
|
-const csvPath = "./test.csv";
|
|
|
|
|
-const outputCsvPath = "./out.csv";
|
|
|
|
|
|
|
+const csvPath = "./test.csv";
|
|
|
|
|
+const outputImagePath = "./out.jpg";
|
|
|
|
|
+const outputCsvPath = "./out.csv";
|
|
|
|
|
|
|
|
let config = {
|
|
let config = {
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
@@ -769,10 +823,17 @@ function encodeFileToBase64(filePath) {
|
|
|
|
|
|
|
|
axios.request(config)
|
|
axios.request(config)
|
|
|
.then((response) => {
|
|
.then((response) => {
|
|
|
- const result = response.data["result"];
|
|
|
|
|
|
|
+ const result = response.data["result"];
|
|
|
|
|
+
|
|
|
|
|
+ // 保存图片文件
|
|
|
|
|
+ const imageBuffer = Buffer.from(result["image"], 'base64');
|
|
|
|
|
+ fs.writeFile(outputImagePath, imageBuffer, (err) => {
|
|
|
|
|
+ if (err) throw err;
|
|
|
|
|
+ console.log(`Output image data saved at ${outputImagePath}`);
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
// 保存csv文件
|
|
// 保存csv文件
|
|
|
- const csvBuffer = Buffer.from(result["csv"], 'base64');
|
|
|
|
|
|
|
+ const csvBuffer = Buffer.from(result["csv"], 'base64');
|
|
|
fs.writeFile(outputCsvPath, csvBuffer, (err) => {
|
|
fs.writeFile(outputCsvPath, csvBuffer, (err) => {
|
|
|
if (err) throw err;
|
|
if (err) throw err;
|
|
|
console.log(`Output time-series data saved at ${outputCsvPath}`);
|
|
console.log(`Output time-series data saved at ${outputCsvPath}`);
|
|
@@ -787,13 +848,14 @@ axios.request(config)
|
|
|
|
|
|
|
|
<pre><code class="language-php"><?php
|
|
<pre><code class="language-php"><?php
|
|
|
|
|
|
|
|
-$API_URL = "http://localhost:8080/time-series-anomaly-detection"; // 服务URL
|
|
|
|
|
-$csv_path = "./test.csv";
|
|
|
|
|
-$output_csv_path = "./out.csv";
|
|
|
|
|
|
|
+$API_URL = "http://localhost:8080/time-series-anomaly-detection"; // 服务URL
|
|
|
|
|
+$csv_path = "./test.csv";
|
|
|
|
|
+$output_image_path = "./out.jpg";
|
|
|
|
|
+$output_csv_path = "./out.csv";
|
|
|
|
|
|
|
|
// 对本地csv文件进行Base64编码
|
|
// 对本地csv文件进行Base64编码
|
|
|
$csv_data = base64_encode(file_get_contents($csv_path));
|
|
$csv_data = base64_encode(file_get_contents($csv_path));
|
|
|
-$payload = array("csv" => $csv_data); // Base64编码的文件内容
|
|
|
|
|
|
|
+$payload = array("csv" => $csv_data); // Base64编码的文件内容
|
|
|
|
|
|
|
|
// 调用API
|
|
// 调用API
|
|
|
$ch = curl_init($API_URL);
|
|
$ch = curl_init($API_URL);
|
|
@@ -805,10 +867,13 @@ $response = curl_exec($ch);
|
|
|
curl_close($ch);
|
|
curl_close($ch);
|
|
|
|
|
|
|
|
// 处理接口返回数据
|
|
// 处理接口返回数据
|
|
|
-$result = json_decode($response, true)["result"];
|
|
|
|
|
|
|
+$result = json_decode($response, true)["result"];
|
|
|
|
|
+
|
|
|
|
|
+file_put_contents($output_image_path, base64_decode($result["image"]));
|
|
|
|
|
+echo "Output image data saved at " . $output_image_path . "\n";
|
|
|
|
|
|
|
|
-file_put_contents($output_csv_path, base64_decode($result["csv"]));
|
|
|
|
|
-echo "Output time-series data saved at " . $output_csv_path . "\n";
|
|
|
|
|
|
|
+file_put_contents($output_csv_path, base64_decode($result["csv"]));
|
|
|
|
|
+echo "Output time-series data saved at " . $output_csv_path . "\n";
|
|
|
|
|
|
|
|
?>
|
|
?>
|
|
|
</code></pre></details>
|
|
</code></pre></details>
|