package com.fshark.overseas.advert.processor;


import com.fshark.overseas.advert.modle.metrics.ActivationMetrics;
import org.apache.flink.api.common.functions.AggregateFunction;

public class ActivationAggregateFunction implements AggregateFunction<ActivationMetrics,ActivationMetrics,ActivationMetrics> {
    @Override
    public ActivationMetrics createAccumulator() {
        return new ActivationMetrics();
    }

    @Override
    public ActivationMetrics add(ActivationMetrics value, ActivationMetrics accumulator) {
        value.setData_activation(value.getData_activation() + accumulator.getData_activation());
        value.setData_register(accumulator.getData_register() + value.getData_register());
        value.setData_device_register(accumulator.getData_device_register() + value.getData_device_register());
        value.setData_create_role(accumulator.getData_create_role() + value.getData_create_role());
        value.setData_day_act_register(accumulator.getData_day_act_register() + value.getData_day_act_register());
        value.setData_day_register_create(accumulator.getData_day_register_create() + value.getData_day_register_create());
        value.setData_active_day_dau(accumulator.getData_active_day_dau() + value.getData_active_day_dau());
        return value;
    }

    @Override
    public ActivationMetrics getResult(ActivationMetrics accumulator) {
        return accumulator;
    }

    @Override
    public ActivationMetrics merge(ActivationMetrics value, ActivationMetrics accumulator) {
        value.setData_activation(accumulator.getData_activation() + value.getData_activation());
        value.setData_register(accumulator.getData_register() + value.getData_register());
        value.setData_device_register(accumulator.getData_device_register() + value.getData_device_register());
        value.setData_create_role(accumulator.getData_create_role() + value.getData_create_role());
        value.setData_day_act_register(accumulator.getData_day_act_register() + value.getData_day_act_register());
        value.setData_day_register_create(accumulator.getData_day_register_create() + value.getData_day_register_create());
        value.setData_active_day_dau(accumulator.getData_active_day_dau() + value.getData_active_day_dau());
        return value;
    }
}
