|
@@ -1,314 +0,0 @@
|
|
|
-package edu.math.diagnosis.word;
|
|
|
-
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.core.io.ClassPathResource;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.InputStreamReader;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-@Component
|
|
|
-public class ExcelUtils {
|
|
|
-
|
|
|
- @Value("${dataPathname:doc/}")
|
|
|
- private String dataPathname = "doc/";
|
|
|
- private List<List<Double>> valves = new ArrayList<>();
|
|
|
- private List<String> ability = new ArrayList<>();
|
|
|
- private List<String> optionWords;
|
|
|
- private Map<String, Map<Integer, String>> words;
|
|
|
- private XSSFSheet sheet;
|
|
|
-
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(ExcelUtils.class);
|
|
|
-
|
|
|
- @PostConstruct
|
|
|
- private boolean init() {
|
|
|
- logger.info("docpath: {} ", dataPathname);
|
|
|
- InputStream is;
|
|
|
- try {
|
|
|
- is = new ClassPathResource(dataPathname + "Data.xlsx").getInputStream();
|
|
|
- } catch (IOException e) {
|
|
|
- logger.error("can not loaded data.xlsx", e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- try (XSSFWorkbook workbook = new XSSFWorkbook(is)) {
|
|
|
- sheet = workbook.getSheetAt(0);
|
|
|
- optionWords = getOptionWords();
|
|
|
- words = getWords();
|
|
|
- ability.addAll(words.keySet());
|
|
|
- List<Double> valve = new ArrayList<>();
|
|
|
- valve.add(3.3);
|
|
|
- valve.add(6.7);
|
|
|
- valve.add(9.0);
|
|
|
- valves.add(valve);
|
|
|
- valve = new ArrayList<>();
|
|
|
- valve.add(2.0);
|
|
|
- valve.add(6.7);
|
|
|
- valve.add(9.0);
|
|
|
- valves.add(valve);
|
|
|
- valve = new ArrayList<>();
|
|
|
- valve.add(3.2);
|
|
|
- valve.add(6.7);
|
|
|
- valve.add(9.0);
|
|
|
- valves.add(valve);
|
|
|
- valve = new ArrayList<>();
|
|
|
- valve.add(1.7);
|
|
|
- valve.add(6.7);
|
|
|
- valve.add(9.0);
|
|
|
- valves.add(valve);
|
|
|
- valve = new ArrayList<>();
|
|
|
- valve.add(3.4);
|
|
|
- valve.add(6.7);
|
|
|
- valve.add(9.0);
|
|
|
- valves.add(valve);
|
|
|
- valve = new ArrayList<>();
|
|
|
- valve.add(2.3);
|
|
|
- valve.add(6.7);
|
|
|
- valves.add(valve);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- public static void main(String[] args) throws IOException {
|
|
|
- System.out.println(System.getProperty("user.dir"));
|
|
|
- ExcelUtils excelUtils = new ExcelUtils();
|
|
|
- Map map1 = excelUtils.getAbilityLevel();
|
|
|
- Map map2 = excelUtils.getAbilityScore();
|
|
|
- Map map3 = excelUtils.getAbilityWords(map1, map2);
|
|
|
- System.out.println();
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> getLines(String pathname) throws IOException {
|
|
|
-// File file = new File(pathname);
|
|
|
- InputStream fis = new ClassPathResource(pathname).getInputStream();
|
|
|
- InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
|
|
|
- BufferedReader br = new BufferedReader(isr);
|
|
|
- String line;
|
|
|
- List<String> lines = new ArrayList<>();
|
|
|
- while ((line = br.readLine()) != null) {
|
|
|
- lines.add(line);
|
|
|
- }
|
|
|
- br.close();
|
|
|
- isr.close();
|
|
|
- fis.close();
|
|
|
- return lines;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, Map<Integer, String>> getWords() throws IOException {
|
|
|
- Map<String, Map<Integer, String>> result = new LinkedHashMap<>();
|
|
|
- List<String> lines = getLines(dataPathname + "word.txt");
|
|
|
- int cnt = 0;
|
|
|
- for (int i = 1; i <= 6; i++) {
|
|
|
- Map<Integer, String> map = new LinkedHashMap<>();
|
|
|
- String key = lines.get(cnt++);
|
|
|
- for (int j = 1; j <= 7; j++) {
|
|
|
- map.put(j, lines.get(cnt++));
|
|
|
- }
|
|
|
- result.put(key, map);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> getOptionWords() throws IOException {
|
|
|
- return getLines(dataPathname + "option.txt");
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, List<Integer>> getAbilityLevel() {
|
|
|
- Map<String, List<Integer>> result = new LinkedHashMap<>();
|
|
|
- List<String> names = getNames();
|
|
|
- for (int i = 1; i <= 20; i++) {
|
|
|
- List<Integer> values = new ArrayList<>(6);
|
|
|
- for (int j = 50; j <= 55; j++) {
|
|
|
- values.add((int) Math.round(sheet.getRow(j).getCell(i).getNumericCellValue()));
|
|
|
- }
|
|
|
- result.put(names.get(i - 1), values);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public List<Double> getCorrectRate() {
|
|
|
- List<Double> rates = new ArrayList<>(20);
|
|
|
- for (int i = 27; i < 47; i++) {
|
|
|
- XSSFRow row = sheet.getRow(i);
|
|
|
- rates.add(row.getCell(0).getNumericCellValue());
|
|
|
- }
|
|
|
- return rates;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, List<Double>> getAbilityScore() {
|
|
|
- Map<String, List<Double>> result = new LinkedHashMap<>();
|
|
|
- List<String> names = getNames();
|
|
|
- for (int i = 1; i <= 20; i++) {
|
|
|
- List<Double> values = new ArrayList<>(6);
|
|
|
- for (int j = 58; j <= 63; j++) {
|
|
|
- values.add(sheet.getRow(j).getCell(i).getNumericCellValue());
|
|
|
- }
|
|
|
- result.put(names.get(i - 1), values);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, List<String>> getPaperOptions() {
|
|
|
- Map<String, List<String>> result = new LinkedHashMap<>();
|
|
|
- List<String> names = getNames();
|
|
|
- int cnt = 1;
|
|
|
- for (String name : names) {
|
|
|
- List<String> options = new ArrayList<>(20);
|
|
|
- for (int i = 6; i < 26; i++) {
|
|
|
- options.add(sheet.getRow(i).getCell(cnt).getStringCellValue());
|
|
|
- }
|
|
|
- result.put(name, options);
|
|
|
- cnt++;
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, List<Integer>> getOptionRw() {
|
|
|
- Map<String, List<Integer>> result = new LinkedHashMap<>();
|
|
|
- List<String> names = getNames();
|
|
|
- int cnt = 1;
|
|
|
- for (String name : names) {
|
|
|
- List<Integer> rw = new ArrayList<>(20);
|
|
|
- for (int i = 27; i < 47; i++) {
|
|
|
- rw.add((int) Math.round(sheet.getRow(i).getCell(cnt).getNumericCellValue()));
|
|
|
- }
|
|
|
- cnt++;
|
|
|
- result.put(name, rw);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, List<String>> getOptionCommentMap(Map<String, List<Integer>> optionMap) {
|
|
|
- Map<String, List<String>> result = new LinkedHashMap<>();
|
|
|
- List<String> names = getNames();
|
|
|
- for (String name : names) {
|
|
|
- List<Integer> options = optionMap.get(name);
|
|
|
- List<String> comments = new ArrayList<>(20);
|
|
|
- for (int i = 0; i < 20; i++) {
|
|
|
- comments.add(optionWords.get(2 * i + 1 - options.get(i)));
|
|
|
- }
|
|
|
- result.put(name, comments);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, List<String>> getAbilityWords(Map<String, List<Integer>> levels, Map<String, List<Double>> scores) {
|
|
|
- Map<String, List<String>> result = new LinkedHashMap<>();
|
|
|
- for (String key : levels.keySet()) {
|
|
|
- List<Integer> level = levels.get(key);
|
|
|
- List<Double> score = scores.get(key);
|
|
|
- List<String> word = new ArrayList<>();
|
|
|
- for (int i = 0; i < 6; i++) {
|
|
|
- int l = level.get(i);
|
|
|
- double s = score.get(i);
|
|
|
- List<Double> valve = valves.get(i);
|
|
|
- if (l == 0) {
|
|
|
- word.add(words.get(ability.get(i)).get(1));
|
|
|
- } else {
|
|
|
- if (s >= valve.get(l - 1)) {
|
|
|
- word.add(words.get(ability.get(i)).get(2 * l + 1));
|
|
|
- } else {
|
|
|
- word.add(words.get(ability.get(i)).get(2 * l));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- result.put(key, word);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> getNames() {
|
|
|
- List<String> names = new ArrayList<>();
|
|
|
- XSSFRow row = sheet.getRow(1);
|
|
|
- int num = row.getLastCellNum();
|
|
|
- for (short i = 1; i < num; i++) {
|
|
|
- names.add(row.getCell(i).getStringCellValue());
|
|
|
- }
|
|
|
- return names;
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> getSchools() {
|
|
|
- List<String> shcools = new ArrayList<>();
|
|
|
- XSSFRow row = sheet.getRow(3);
|
|
|
- int num = row.getLastCellNum();
|
|
|
- for (short i = 1; i < num; i++) {
|
|
|
- shcools.add(row.getCell(i).getStringCellValue());
|
|
|
- }
|
|
|
- return shcools;
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> getTeachers() {
|
|
|
- List<String> teachers = new ArrayList<>();
|
|
|
- XSSFRow row = sheet.getRow(4);
|
|
|
- int num = row.getLastCellNum();
|
|
|
- for (short i = 1; i < num; i++) {
|
|
|
- teachers.add(row.getCell(i).getStringCellValue());
|
|
|
- }
|
|
|
- return teachers;
|
|
|
- }
|
|
|
-
|
|
|
- public List<Double> getAbilityAveScore() {
|
|
|
- List<Double> result = new ArrayList<>(6);
|
|
|
- for (int i = 89; i < 95; i++) {
|
|
|
- result.add(sheet.getRow(i).getCell(1).getNumericCellValue());
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public List<Double> getCurveGraph() {
|
|
|
- List<Double> result = new ArrayList<>(101);
|
|
|
- for (int i = 90; i < 191; i++) {
|
|
|
- result.add(sheet.getRow(i).getCell(4).getNumericCellValue());
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> getCorrectAns() {
|
|
|
- List<String> ans = new ArrayList<>(20);
|
|
|
- for (int i = 6; i <= 25; i++) {
|
|
|
- XSSFRow row = sheet.getRow(i);
|
|
|
- ans.add(row.getCell(0).getStringCellValue());
|
|
|
- }
|
|
|
- return ans;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, Integer> getTotalScore() {
|
|
|
- Map<String, Integer> result = new LinkedHashMap<>();
|
|
|
- List<String> names = getNames();
|
|
|
- int cnt = 1;
|
|
|
- int row = 48;
|
|
|
- for (String name : names) {
|
|
|
- int score = (int) sheet.getRow(row).getCell(cnt++).getNumericCellValue();
|
|
|
- result.put(name, score);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public Map<String, List<String>> getOptions() {
|
|
|
- Map<String, List<String>> result = new LinkedHashMap<>();
|
|
|
- List<String> names = getNames();
|
|
|
- for (int i = 1; i <= 20; i++) {
|
|
|
- List<String> options = new ArrayList<>(20);
|
|
|
- for (int j = 6; j <= 25; j++) {
|
|
|
- options.add(sheet.getRow(j).getCell(i).getStringCellValue());
|
|
|
- }
|
|
|
- result.put(names.get(i - 1), options);
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-}
|