Search in sources :

Example 1 with Record

use of mingzuozhibi.persist.disc.Record in project mzzb-server by mingzuozhibi.

the class SakuraHelper method buildRecords.

public static JSONArray buildRecords(Dao dao, Disc disc) {
    JSONArray array = new JSONArray();
    @SuppressWarnings("unchecked") List<Record> records = dao.create(Record.class).add(Restrictions.eq("disc", disc)).addOrder(Order.desc("date")).list();
    records.forEach(record -> {
        JSONObject object = new JSONObject();
        object.put("id", record.getId());
        object.put("date", record.getDate());
        object.put("todayPt", record.getTodayPt());
        object.put("totalPt", record.getTotalPt());
        getAverRank(record).ifPresent(averRank -> {
            object.put("averRank", (int) averRank);
        });
        array.put(object);
    });
    return array;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Record(mingzuozhibi.persist.disc.Record)

Example 2 with Record

use of mingzuozhibi.persist.disc.Record in project mzzb-server by mingzuozhibi.

the class SakuraHelper method mergeRankText.

public static int mergeRankText(Dao dao, Disc disc, String text) {
    String regex = "【(\\d{4})年 (\\d{2})月 (\\d{2})日 (\\d{2})時\\(.\\)】 ([*,\\d]{7})位";
    Pattern pattern = Pattern.compile(regex);
    String[] strings = text.split("\n");
    int matchLine = 0;
    for (String string : strings) {
        Matcher matcher = pattern.matcher(string);
        if (matcher.find()) {
            Integer rank = parseNumber(matcher.group(5));
            if (rank == null) {
                continue;
            }
            int year = Integer.parseInt(matcher.group(1));
            int month = Integer.parseInt(matcher.group(2));
            int date = Integer.parseInt(matcher.group(3));
            int hour = Integer.parseInt(matcher.group(4));
            LocalDate localDate = LocalDate.of(year, month, date);
            Record record = getOrCreateRecord(dao, disc, localDate);
            record.setRank(hour, rank);
            matchLine++;
        }
    }
    return matchLine;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Record(mingzuozhibi.persist.disc.Record) LocalDate(java.time.LocalDate)

Example 3 with Record

use of mingzuozhibi.persist.disc.Record in project mzzb-server by mingzuozhibi.

the class HourlyMission method recordDiscsRankAndComputePt.

public void recordDiscsRankAndComputePt() {
    // +9 timezone and prev hour, so +1h -1h = +0h
    LocalDateTime recordTime = LocalDateTime.now();
    LocalDate date = recordTime.toLocalDate();
    int hour = recordTime.getHour();
    dao.execute(session -> {
        @SuppressWarnings("unchecked") List<Sakura> sakuras = session.createCriteria(Sakura.class).add(Restrictions.ne("key", "9999-99")).add(Restrictions.eq("enabled", true)).list();
        Set<Disc> discs = new LinkedHashSet<>();
        sakuras.forEach(sakura -> {
            sakura.getDiscs().stream().filter(disc -> disc.getUpdateType() != UpdateType.None).filter(SakuraHelper::noExpiredDisc).forEach(discs::add);
        });
        LOGGER.info("[定时任务][记录碟片排名][碟片数量为:{}]", discs.size());
        discs.forEach(disc -> {
            Record record = getOrCreateRecord(dao, disc, date);
            record.setRank(hour, disc.getThisRank());
            record.setTotalPt(disc.getTotalPt());
        });
        LOGGER.info("[定时任务][计算碟片PT][碟片数量为:{}]", discs.size());
        discs.forEach(disc -> {
            if (disc.getUpdateType() != UpdateType.Sakura) {
                computeAndUpdateAmazonPt(dao, disc);
            } else {
                computeAndUpdateSakuraPt(dao, disc);
            }
        });
    });
}
Also used : LocalDateTime(java.time.LocalDateTime) LinkedHashSet(java.util.LinkedHashSet) Disc(mingzuozhibi.persist.disc.Disc) Record(mingzuozhibi.persist.disc.Record) Sakura(mingzuozhibi.persist.disc.Sakura) LocalDate(java.time.LocalDate)

Example 4 with Record

use of mingzuozhibi.persist.disc.Record in project mzzb-server by mingzuozhibi.

the class SakuraHelper method mergePtText.

public static int mergePtText(Dao dao, Disc disc, String text) {
    String regex = "【(\\d{4})年 (\\d{2})月 (\\d{2})日\\(.\\)】 ([*,\\d]{7})";
    Pattern pattern = Pattern.compile(regex);
    String[] strings = text.split("\n");
    int matchLine = 0;
    for (String string : strings) {
        Matcher matcher = pattern.matcher(string);
        if (matcher.find()) {
            Integer totalPt = parseNumber(matcher.group(4));
            if (totalPt == null) {
                continue;
            }
            int year = Integer.parseInt(matcher.group(1));
            int month = Integer.parseInt(matcher.group(2));
            int date = Integer.parseInt(matcher.group(3));
            LocalDate localDate = LocalDate.of(year, month, date);
            Record record = getOrCreateRecord(dao, disc, localDate);
            record.setTotalPt(totalPt);
            matchLine++;
        }
    }
    return matchLine;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Record(mingzuozhibi.persist.disc.Record) LocalDate(java.time.LocalDate)

Example 5 with Record

use of mingzuozhibi.persist.disc.Record in project mzzb-server by mingzuozhibi.

the class SakuraHelper method getOrCreateRecord.

public static Record getOrCreateRecord(Dao dao, Disc disc, LocalDate date) {
    Record record = (Record) dao.create(Record.class).add(Restrictions.eq("disc", disc)).add(Restrictions.eq("date", date)).uniqueResult();
    if (record == null) {
        record = new Record(disc, date);
        dao.save(record);
    }
    return record;
}
Also used : Record(mingzuozhibi.persist.disc.Record)

Aggregations

Record (mingzuozhibi.persist.disc.Record)5 LocalDate (java.time.LocalDate)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 LocalDateTime (java.time.LocalDateTime)1 LinkedHashSet (java.util.LinkedHashSet)1 Disc (mingzuozhibi.persist.disc.Disc)1 Sakura (mingzuozhibi.persist.disc.Sakura)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1