<commit_before>package roart.action;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Calendar;
//import java.util.Collections;
//import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import roart.component.Component;
import roart.component.ComponentFactory;
import roart.config.IclijConfig;
import roart.config.IclijXMLConfig;
import roart.config.Market;
import roart.config.TradeMarket;
import roart.db.IclijDbDao;
import roart.model.IncDecItem;
import roart.model.MemoryItem;
import roart.model.ResultMeta;
import roart.pipeline.PipelineConstants;
import roart.service.ControlService;
import roart.util.Constants;

public class FindProfitAction extends Action {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    public static final String TP = "TP";
    public static final String TN = "TN";
    public static final String FP = "FP";
    public static final String FN = "FN";

    @Override
    public void goal(Action parent) {

        // find recommended picks

        IclijConfig config = IclijXMLConfig.getConfigInstance();
        boolean save = true;
        List<TradeMarket> markets = getMarkets();
        for (TradeMarket market : markets) {
            LocalDate olddate = LocalDate.now();        
            olddate = olddate.minusDays(market.getRecordage());
            List<MemoryItem> marketMemory = getMarketMemory(market.getMarket());
            getPicks(market, save, olddate, marketMemory, config);
        }
    }

    public Map<String, IncDecItem>[] getPicks(String market, boolean save, LocalDate date, List<MemoryItem> memoryItems, IclijConfig config) {
        List<TradeMarket> markets = getMarkets();
        TradeMarket foundTradeMarket = null;
        // TODO check if two markets
        for (TradeMarket aTradeMarket : markets) {
            if (market.equals(aTradeMarket.getMarket())) {
                foundTradeMarket = aTradeMarket;
                break;
            }
        }
        if (foundTradeMarket == null) {
            Map<String, IncDecItem>[] buysell = new Map[2];
            Map<String, IncDecItem> buys = new HashMap<>();
            Map<String, IncDecItem> sells = new HashMap<>();
            buysell[0] = buys;
            buysell[1] = sells;
            return buysell;
        }
        return getPicks(foundTradeMarket, save, date, memoryItems, config);
    }
    
    private Map<String, IncDecItem>[] getPicks(TradeMarket market, boolean save, LocalDate olddate, List<MemoryItem> marketMemory, IclijConfig config) {
        Map<String, IncDecItem>[] buysell = new Map[2];
        if (marketMemory == null) {
            return buysell;
        }

        List<MemoryItem> currentList = filterKeepRecent(marketMemory, olddate);
        // or make a new object instead of the object array. use this as a pair
        //System.out.println(currentList.get(0).getRecord());
        Map<Object[], List<MemoryItem>> listMap = new HashMap<>();
        // map subcat + posit -> list
        currentList.forEach(m -> listGetterAdder(listMap, new Object[]{m.getComponent(), m.getPosition() }, m));
        Map<Object[], List<MemoryItem>> okListMap = new HashMap<>();
        Map<Object[], Double> okConfMap = new HashMap<>();
        filterMemoryListMapsWithConfidence(market, listMap, okListMap, okConfMap);
        Map<String, List<Integer>> listComponent = createComponentPositionListMap(okListMap);
        ControlService srv = new ControlService();
        srv.getConfig();
        srv.conf.setMarket(market.getMarket());
        Map<String, Component> componentMap = getComponentMap(listComponent);

        Map<String, IncDecItem> buys = new HashMap<>();
        Map<String, IncDecItem> sells = new HashMap<>();
        Component.disabler(srv.conf);
        Map<String, Map<String, Object>> result0 = srv.getContent();
        Map<String, Map<String, Object>> maps = result0;
        Map<String, String> nameMap = getNameMap(maps);
        handleComponent(okListMap, okConfMap, listComponent, srv, componentMap, buys, sells, maps, nameMap, config);
        String category = market.getInccategory();
        Double threshold = market.getIncthreshold();
        Map<String, Object> categoryMap = maps.get(category);
        Map<String, List<List>> listMap3 = getCategoryList(maps, category);
        Map<String, IncDecItem> buysFilter = buyFilterOnIncreaseValue(market, buys, maps, threshold, categoryMap,
                listMap3);
        buys = buysFilter;<commit_msg>Null check.<commit_after>package roart.action;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Calendar;
//import java.util.Collections;
//import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import roart.component.Component;
import roart.component.ComponentFactory;
import roart.config.IclijConfig;
import roart.config.IclijXMLConfig;
import roart.config.Market;
import roart.config.TradeMarket;
import roart.db.IclijDbDao;
import roart.model.IncDecItem;
import roart.model.MemoryItem;
import roart.model.ResultMeta;
import roart.pipeline.PipelineConstants;
import roart.service.ControlService;
import roart.util.Constants;

public class FindProfitAction extends Action {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    public static final String TP = "TP";
    public static final String TN = "TN";
    public static final String FP = "FP";
    public static final String FN = "FN";

    @Override
    public void goal(Action parent) {

        // find recommended picks

        IclijConfig config = IclijXMLConfig.getConfigInstance();
        boolean save = true;
        List<TradeMarket> markets = getMarkets();
        for (TradeMarket market : markets) {
            LocalDate olddate = LocalDate.now();        
            olddate = olddate.minusDays(market.getRecordage());
            List<MemoryItem> marketMemory = getMarketMemory(market.getMarket());
            getPicks(market, save, olddate, marketMemory, config);
        }
    }

    public Map<String, IncDecItem>[] getPicks(String market, boolean save, LocalDate date, List<MemoryItem> memoryItems, IclijConfig config) {
        List<TradeMarket> markets = getMarkets();
        TradeMarket foundTradeMarket = null;
        // TODO check if two markets
        for (TradeMarket aTradeMarket : markets) {
            if (market.equals(aTradeMarket.getMarket())) {
                foundTradeMarket = aTradeMarket;
                break;
            }
        }
        if (foundTradeMarket == null) {
            Map<String, IncDecItem>[] buysell = new Map[2];
            Map<String, IncDecItem> buys = new HashMap<>();
            Map<String, IncDecItem> sells = new HashMap<>();
            buysell[0] = buys;
            buysell[1] = sells;
            return buysell;
        }
        return getPicks(foundTradeMarket, save, date, memoryItems, config);
    }
    
    private Map<String, IncDecItem>[] getPicks(TradeMarket market, boolean save, LocalDate olddate, List<MemoryItem> marketMemory, IclijConfig config) {
        Map<String, IncDecItem>[] buysell = new Map[2];
        if (marketMemory == null) {
            return buysell;
        }

        List<MemoryItem> currentList = filterKeepRecent(marketMemory, olddate);
        // or make a new object instead of the object array. use this as a pair
        //System.out.println(currentList.get(0).getRecord());
        Map<Object[], List<MemoryItem>> listMap = new HashMap<>();
        // map subcat + posit -> list
        currentList.forEach(m -> listGetterAdder(listMap, new Object[]{m.getComponent(), m.getPosition() }, m));
        Map<Object[], List<MemoryItem>> okListMap = new HashMap<>();
        Map<Object[], Double> okConfMap = new HashMap<>();
        filterMemoryListMapsWithConfidence(market, listMap, okListMap, okConfMap);
        Map<String, List<Integer>> listComponent = createComponentPositionListMap(okListMap);
        ControlService srv = new ControlService();
        srv.getConfig();
        srv.conf.setMarket(market.getMarket());
        Map<String, Component> componentMap = getComponentMap(listComponent);

        Map<String, IncDecItem> buys = new HashMap<>();
        Map<String, IncDecItem> sells = new HashMap<>();
        Component.disabler(srv.conf);
        Map<String, Map<String, Object>> result0 = srv.getContent();
        Map<String, Map<String, Object>> maps = result0;
        Map<String, String> nameMap = getNameMap(maps);
        handleComponent(okListMap, okConfMap, listComponent, srv, componentMap, buys, sells, maps, nameMap, config);
        String category = market.getInccategory();
        if (category != null) {
            Double threshold = market.getIncthreshold();
            Map<String, Object> categoryMap = maps.get(category);
            Map<String, List<List>> listMap3 = getCategoryList(maps, category);
            Map<String, IncDecItem> buysFilter = buyFilterOnIncreaseValue(market, buys, maps, threshold, categoryMap,
                    listMap3);
            buys = buysFilter;
        }
{'fraction_non_alphanumeric': 0.11043008518595471, 'fraction_numerical': 0.0022854768335757326, 'mean_word_length': 3.1585313174946004, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2276189', 'n_tokens_mistral': 2810, 'n_tokens_neox': 2700, 'n_words': 673}