package com.tzld.piaoquan.recommend.server.framework.userattention;


import com.tzld.piaoquan.recommend.server.framework.common.User;
import com.tzld.piaoquan.recommend.server.framework.common.UserAttention;
import com.tzld.piaoquan.recommend.server.gen.recommend.RecommendRequest;

import java.util.ArrayList;
import java.util.List;

public class UserAttentionExtractorPipeline {
    private List<AbstractUserAttentionExtractor> extractorList = new ArrayList<AbstractUserAttentionExtractor>();

    public UserAttentionExtractorPipeline(List<AbstractUserAttentionExtractor> extractorList) {
        this.extractorList = extractorList;
    }

    public void extractAttention(final RecommendRequest requestData, final User user) {
        if (user.getUserAttention() == null) {
            UserAttention userAttention = new UserAttention();
            user.setUserAttention(userAttention);
        }

        long startTime = System.currentTimeMillis();

        for (AbstractUserAttentionExtractor extractor : extractorList) {
            try {
                long currStartTime = System.currentTimeMillis();
                extractor.extractAttention(requestData, user);
                // log
            } catch (Exception e) {
                // log
            }
        }
    }
}