<commit_before>package com.neverwinterdp.analytics.web;

import java.security.MessageDigest;
import java.util.Date;

import javax.xml.bind.annotation.adapters.HexBinaryAdapter;

import com.neverwinterdp.message.Message;
import com.neverwinterdp.scribengin.dataflow.DataStreamOperator;
import com.neverwinterdp.scribengin.dataflow.DataStreamOperatorContext;
import com.neverwinterdp.util.JSONSerializer;
import com.neverwinterdp.util.UrlParser;

public class WebEventOperator extends DataStreamOperator {
  private MessageDigest md5Digest ;
  private HexBinaryAdapter hexBinaryAdapter = new HexBinaryAdapter();
  public void onInit(DataStreamOperatorContext ctx) throws Exception {
    md5Digest = MessageDigest.getInstance("MD5");
  }
  
  public void onPostCommit(DataStreamOperatorContext ctx) throws Exception {
  }
  
  @Override
  public void process(DataStreamOperatorContext ctx, Message mesg) throws Exception {
    WebEvent webEvent = JSONSerializer.INSTANCE.fromBytes(mesg.getData(), WebEvent.class) ;
    UrlParser urlParser = new UrlParser(webEvent.getClientInfo().webpage.url);
    
    WebpageVisit wVisit = new WebpageVisit();
    if(urlParser.getHost().startsWith("host:www.website-")) {
      wVisit.setSource("generator");
    }
    wVisit.setEventId(webEvent.getEventId());
    wVisit.setTimestamp(new Date(webEvent.getTimestamp()));
    wVisit.setHost(urlParser.getHost());
    wVisit.setPath(urlParser.getPath());
    wVisit.setVisitorId(webEvent.getClientInfo().user.visitorId);
    wVisit.setVisitorRegion(webEvent.getClientInfo().geoLocation.region);
    wVisit.setVisitorLatitude(webEvent.getClientInfo().geoLocation.latitude);
    wVisit.setVisitorLongitude(webEvent.getClientInfo().geoLocation.longitude);
    wVisit.setClientIpAddress(webEvent.getClientInfo().user.ipAddress);

    byte[] bytes = md5Digest.digest((urlParser.getUrl() + "#" + wVisit.getVisitorId()).getBytes());
    wVisit.setVisitId(hexBinaryAdapter.marshal(bytes));

    wVisit.logSpentTime(webEvent.getClientInfo().user.spentTime);
    mesg.setData(JSONSerializer.INSTANCE.toBytes(wVisit));
    ctx.write(mesg);<commit_msg>fix source tag<commit_after>package com.neverwinterdp.analytics.web;

import java.security.MessageDigest;
import java.util.Date;

import javax.xml.bind.annotation.adapters.HexBinaryAdapter;

import com.neverwinterdp.message.Message;
import com.neverwinterdp.scribengin.dataflow.DataStreamOperator;
import com.neverwinterdp.scribengin.dataflow.DataStreamOperatorContext;
import com.neverwinterdp.util.JSONSerializer;
import com.neverwinterdp.util.UrlParser;

public class WebEventOperator extends DataStreamOperator {
  private MessageDigest md5Digest ;
  private HexBinaryAdapter hexBinaryAdapter = new HexBinaryAdapter();
  public void onInit(DataStreamOperatorContext ctx) throws Exception {
    md5Digest = MessageDigest.getInstance("MD5");
  }
  
  public void onPostCommit(DataStreamOperatorContext ctx) throws Exception {
  }
  
  @Override
  public void process(DataStreamOperatorContext ctx, Message mesg) throws Exception {
    WebEvent webEvent = JSONSerializer.INSTANCE.fromBytes(mesg.getData(), WebEvent.class) ;
    UrlParser urlParser = new UrlParser(webEvent.getClientInfo().webpage.url);
    
    WebpageVisit wVisit = new WebpageVisit();
    if(urlParser.getHost().startsWith("www.website-")) {
      wVisit.setSource("generator");
    }
    wVisit.setEventId(webEvent.getEventId());
    wVisit.setTimestamp(new Date(webEvent.getTimestamp()));
    wVisit.setHost(urlParser.getHost());
    wVisit.setPath(urlParser.getPath());
    wVisit.setVisitorId(webEvent.getClientInfo().user.visitorId);
    wVisit.setVisitorRegion(webEvent.getClientInfo().geoLocation.region);
    wVisit.setVisitorLatitude(webEvent.getClientInfo().geoLocation.latitude);
    wVisit.setVisitorLongitude(webEvent.getClientInfo().geoLocation.longitude);
    wVisit.setClientIpAddress(webEvent.getClientInfo().user.ipAddress);

    byte[] bytes = md5Digest.digest((urlParser.getUrl() + "#" + wVisit.getVisitorId()).getBytes());
    wVisit.setVisitId(hexBinaryAdapter.marshal(bytes));

    wVisit.logSpentTime(webEvent.getClientInfo().user.spentTime);
    mesg.setData(JSONSerializer.INSTANCE.toBytes(wVisit));
    ctx.write(mesg);
{'fraction_non_alphanumeric': 0.11213408876298395, 'fraction_numerical': 0.0018885741265344666, 'mean_word_length': 5.86709886547812, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '381915', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1276, 'n_words': 173}