12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package com.fdkk.fdkkmeta.test;
- import cn.hutool.core.date.DateUtil;
- import cn.hutool.core.io.file.FileWriter;
- import cn.hutool.core.util.URLUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkk.fdkkmeta.po.RoutePO;
- import com.fdkk.fdkkmeta.util.FileUtils;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.nio.charset.Charset;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * @author Xiewj
- * @date 2022/3/29
- */
- public class test {
- // public static void main(String[] args) throws IOException {
- // int d=6;
- // int fps=2 % d;
- // if (fps!=0){
- // fps=2/d+1;
- // }
- //
- // System.out.println(fps);
- //
- // }
- public static void main(String[] args) throws IOException {
- String path="C:\\Users\\4DAGE\\Downloads\\final_freespace(1).csv";
- createdPointsJson(path);
- creatTargetJson(path);
- }
- private static void createdPointsJson(String path) {
- List<String> list = FileUtils.readFileByLines2(path);
- JSONArray array=new JSONArray();
- FileWriter writer=new FileWriter("D:\\video\\points.json");
- for (int i = 0; i < list.size(); i++) {
- JSONObject jsonObject=new JSONObject();
- String[] s = list.get(i).split(" ");
- jsonObject.put("id",i );
- JSONObject position=new JSONObject();
- position.put("x",Double.valueOf(s[0]));
- position.put("y",Double.valueOf(s[1]));
- position.put("z",Double.valueOf(s[2]));
- jsonObject.put("position",position);
- JSONObject rotation=new JSONObject();
- rotation.put("x",0.0);
- rotation.put("y",0.0);
- rotation.put("z",0.0);
- rotation.put("w",1.0);
- jsonObject.put("rotation",rotation);
- List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
- List<Integer> contact = strings.stream().filter(a -> !a.equals("-1")).map(a->{
- return Integer.parseInt(a)-1;
- }).collect(Collectors.toList());
- jsonObject.put("contact",contact);
- array.add(jsonObject);
- }
- writer.write(array.toJSONString());
- }
- private static void creatTargetJson(String path) {
- List<String> list = FileUtils.readFileByLines2(path);
- List<String> collect = new ArrayList<>();
- FileWriter writer=new FileWriter("D:\\video\\target_freespace.json");
- for (int i = 0; i < list.size(); i++) {
- RoutePO po = new RoutePO();
- String[] s = list.get(i).split(" ");
- po.setId(i );
- if (s.length == 12) {
- double[] oldPoint = {Double.valueOf(s[0]), Double.valueOf(s[1]), Double.valueOf(s[2])};
- po.setX(oldPoint[0]);
- po.setY(oldPoint[1]);
- po.setZ(oldPoint[2]);
- po.setWeight(Double.parseDouble(s[3]));
- List<String> strings = Arrays.asList(s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11]);
- List<Integer> contact = strings.stream().map(a->{
- if (Integer.parseInt(a)!=-1){
- return Integer.parseInt(a)-1;
- }
- return Integer.parseInt(a);
- }).collect(Collectors.toList());
- po.setIds(contact);
- }
- collect.add(JSON.toJSONString(po));
- }
- writer.writeLines(collect);
- }
- }
|