Example #1
0
        /// <summary>
        /// Channel logger constructor.
        /// </summary>
        /// <param name="channelId">Unique logger id</param>
        /// <param name="stream">Logging stream. Should be writable.</param>
        /// <param name="buffer">Serialization buffer. Can be shared between multiple loggers (non thread safe).</param>
        /// <param name="tracer">Optional realtime message tracer. Useful in debug environment.</param>
        /// <exception cref="BinLogException">
        /// Thrown when size of <c>TChannelEnum</c> or <c>TMessageEnum</c> is invalid.
        /// </exception>
        protected Logger(TChannelEnum channelId, Stream stream, byte[] buffer, LogTracer tracer = null)
        {
            if (!LogEnum.CheckSizeOf <TChannelEnum>())
            {
                throw new BinLogException($"Size of {nameof(TChannelEnum)} should be {sizeof(ushort)}");
            }

            if (!LogEnum.CheckSizeOf <TMessageEnum>())
            {
                throw new BinLogException($"Size of {nameof(TMessageEnum)} should be {sizeof(ushort)}");
            }

            _stream = stream;
            _buffer = buffer;

            if (!_stream.CanWrite)
            {
                throw new BinLogException("Stream doesn't support writing");
            }

            _tracer = tracer;
            _name   = channelId.ToString();

            _channelId = LogEnum.ToUInt16(channelId);
        }
Example #2
0
        public CoinSnapshotSetBase(bool isPull, IClientDataSetBase clientSet)
        {
            _isPull    = isPull;
            _clientSet = clientSet;
            LogEnum logType = isPull ? LogEnum.None : LogEnum.UserConsole;

            VirtualRoot.BuildEventPath <Per10SecondEvent>("周期性拍摄快照", logType,
                                                          path: message => {
                Snapshot(message.BornOn);
            }, location: this.GetType());
            VirtualRoot.BuildEventPath <Per2MinuteEvent>("周期性移除内存中20分钟前的快照", logType,
                                                         path: message => {
                DateTime time = message.BornOn.AddMinutes(-20);
                var toRemoves = _dataList.Where(a => a.Timestamp < time).ToArray();
                foreach (var item in toRemoves)
                {
                    _dataList.Remove(item);
                }
            }, location: this.GetType());
            VirtualRoot.BuildEventPath <HasBoot1MinuteEvent>("启动一会儿后清理一下很长时间之前的算力报告数据库文件", logType, path: message => {
                ClearReportDbFiles(message.BornOn);
            }, this.GetType());
            VirtualRoot.BuildEventPath <Per24HourEvent>("每24小时清理一下很长时间之前的算力报告数据库文件", logType, path: message => {
                ClearReportDbFiles(message.BornOn);
            }, this.GetType());
        }
Example #3
0
        private static void WriteLog(string msg,LogEnum logType,Exception ex)
        {
            if (provider != null) {
                switch (logType)
                {
                    case LogEnum.Debug:
                        provider.Debug(msg,ex);
                        break;
                    case LogEnum.Error:
                        provider.Error(msg,ex);
                        break;
                    case LogEnum.Fatal:
                        provider.Fatal(msg,ex);
                        break;
                    case LogEnum.Info:
                        provider.Info(msg,ex);
                        break;
                    case LogEnum.Warn:
                        provider.Warn(msg,ex);
                        break;
                    default:
                        return;

                }
            }
        }
Example #4
0
        /// <summary>
        /// 将日志信息写入文件
        /// </summary>
        /// <param name="fileName">文件名称</param>
        /// <param name="message">日志内容</param>
        private static void _WriteLog(LogEnum e, string message)
        {
            string fileName = string.Empty;

            switch (e)
            {
            case LogEnum.INFO:
                fileName = $"Info_{DateTime.Now.ToString("yyyyMMdd")}.log";
                //string.Format("Info_{0}.log", DateTime.Now.ToString("yyyyMMdd"));
                break;

            default:
                fileName = $"Error_{DateTime.Now.ToString("yyyyMMdd")}.log";
                //string.Format("Error_{0}.log", DateTime.Now.ToString("yyyyMMdd"));
                break;
            }
            lock (objLock)
            {
                using (FileStream fs = File.Open(Path.Combine(logPath, fileName), FileMode.Append, FileAccess.Write, FileShare.None))
                {
                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        sw.WriteLine(string.Format("{0} --- 线程:{1} --- {2} ", DateTime.Now.ToString().PadRight(20), Thread.CurrentThread.ManagedThreadId.ToString().PadRight(2), message));
                        sw.Flush();
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// 事件响应
        /// </summary>
        private void AddEventPath <TEvent>(string description, LogEnum logType, Action <TEvent> action, Type location)
            where TEvent : IEvent
        {
            var messagePathId = VirtualRoot.AddMessagePath(description, logType, action, location);

            _contextPathIds.Add(messagePathId);
        }
        public void WriteLog(LogEnum name, LogLevel level, string logContent)
        {
            log = log4net.LogManager.GetLogger(name.ToString());
            //log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            switch (level)
            {
                case LogLevel.DEBUG:
                    log.Debug(logContent);
                    break;
                case LogLevel.ERROR:
                    log.Error(logContent);
                    break;
                case LogLevel.FATAL:
                    log.Fatal(logContent);
                    break;
                case LogLevel.INFO:
                    log.Info(logContent);
                    break;
                case LogLevel.WARN:
                    log.Warn(logContent);
                    break;
                default:
                    log.Debug(logContent);
                    break;
            }
        }
Example #7
0
        private static void WriteLog(string msg, LogEnum logType, Exception ex)
        {
            if (provider != null)
            {
                switch (logType)
                {
                case LogEnum.Debug:
                    provider.Debug(msg, ex);
                    break;

                case LogEnum.Error:
                    provider.Error(msg, ex);
                    break;

                case LogEnum.Fatal:
                    provider.Fatal(msg, ex);
                    break;

                case LogEnum.Info:
                    provider.Info(msg, ex);
                    break;

                case LogEnum.Warn:
                    provider.Warn(msg, ex);
                    break;

                default:
                    return;
                }
            }
        }
Example #8
0
    /// <summary>
    /// 基础日志答应
    /// </summary>
    /// <param name="title">标题提示</param>
    /// <param name="content">内容</param>
    /// <param name="type">类型 详情见LogEnum</param>
    /// <returns></returns>
    private static string BaseDebugLog(string title, string content, LogEnum type)
    {
        //如果没有开启日志输出 则放弃打印
        if (!ProjectConfigInfo.IS_OPEN_LOG_MSG)
        {
            return(null);
        }
        string logMsg = title + content;

        //根据不同的日志类型答应不同的日志
        switch (type)
        {
        case LogEnum.Normal:
            Debug.Log(logMsg);
            break;

        case LogEnum.Warning:
            Debug.LogWarning(logMsg);
            break;

        case LogEnum.Error:
            Debug.LogError(logMsg);
            break;
        }
        return(logMsg);
    }
Example #9
0
        public void WriteLog(LogEnum name, LogLevel level, string logContent)
        {
            log = log4net.LogManager.GetLogger(name.ToString());
            //log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            switch (level)
            {
            case LogLevel.DEBUG:
                log.Debug(logContent);
                break;

            case LogLevel.ERROR:
                log.Error(logContent);
                break;

            case LogLevel.FATAL:
                log.Fatal(logContent);
                break;

            case LogLevel.INFO:
                log.Info(logContent);
                break;

            case LogLevel.WARN:
                log.Warn(logContent);
                break;

            default:
                log.Debug(logContent);
                break;
            }
        }
Example #10
0
        // 因为是上下文路径,无需返回路径标识
        public static void BuildEventPath <TEvent>(string description, LogEnum logType, Type location, PathPriority priority, Action <TEvent> path)
            where TEvent : IEvent
        {
            var messagePathId = VirtualRoot.BuildMessagePath(description, logType, location, priority, path);

            _contextPathIds.Add(messagePathId);
        }
Example #11
0
        /// <summary>
        /// 命令窗口。使用该方法的代码行应将前两个参数放在第一行以方便vs查找引用时展示出参数信息
        /// </summary>
        public void BuildCmdPath <TCmd>(string description, LogEnum logType, Action <TCmd> action)
            where TCmd : ICmd
        {
            var messagePathId = VirtualRoot.BuildPath(description, logType, action);

            _serverContextHandlers.Add(messagePathId);
        }
Example #12
0
        /// <summary>
        /// 事件响应
        /// </summary>
        public void BuildEventPath <TEvent>(string description, LogEnum logType, Action <TEvent> action)
            where TEvent : IEvent
        {
            var messagePathId = VirtualRoot.BuildPath(description, logType, action);

            _serverContextHandlers.Add(messagePathId);
        }
Example #13
0
 public TextLog(string _content)
 {
     logType         = LogEnum.Error;
     timeGranularity = TimeGranularity.Daily;
     content         = _content;
     lastWriteTime   = DateTime.Now;
 }
Example #14
0
 public TextLog(LogEnum _logType, TimeGranularity _timeGranularity, string _content)
 {
     logType         = _logType;
     timeGranularity = _timeGranularity;
     content         = _content;
     lastWriteTime   = DateTime.Now;
 }
Example #15
0
        /// <summary>
        /// 获取记录器
        /// </summary>
        /// <param name="type_log"></param>
        /// <returns></returns>
        public ILog GetLog(LogEnum type_log)
        {
            var name = type_log.ToString();
            var log  = LogManager.GetLogger(name);

            return(new Log(log, LogManager.GetLogger("net_" + name)));
        }
Example #16
0
        public void Log <T1, T2, T3, T4>(LogLevel level, TMessageEnum msgId, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
            where T1 : ILoggableValue
            where T2 : ILoggableValue
            where T3 : ILoggableValue
            where T4 : ILoggableValue
        {
            _tracer?.Trace(level, _name, LogEnum.GetMsg(msgId), arg1.Unwrap(), arg2.Unwrap(), arg3.Unwrap(), arg4.Unwrap());

            var length = EntryHeader.Size + arg1.SizeOf() + arg2.SizeOf() + arg3.SizeOf() + arg4.SizeOf();
            var header = new EntryHeader((ushort)length, _channelId, LogEnum.ToUInt16(msgId), level, 4);

            var span = GetSpan(length);

            var bytesWritten = header.WriteTo(span);

            bytesWritten += arg1.WriteTo(span.Slice(bytesWritten));
            bytesWritten += arg2.WriteTo(span.Slice(bytesWritten));
            bytesWritten += arg3.WriteTo(span.Slice(bytesWritten));
            bytesWritten += arg4.WriteTo(span.Slice(bytesWritten));

            if (bytesWritten != length)
            {
                throw new SerializationException("Failed to serialize log entry");
            }

            _stream.Write(_buffer, 0, bytesWritten);
        }
Example #17
0
        /// <summary>
        /// 命令窗口。使用该方法的代码行应将前两个参数放在第一行以方便vs查找引用时展示出参数信息
        /// </summary>
        public void AddCmdPath <TCmd>(LogEnum logType, Action <TCmd> action, Type location)
            where TCmd : ICmd
        {
            var messagePathId = VirtualRoot.BuildCmdPath(action, location, logType);

            _contextPathIds.Add(messagePathId);
        }
Example #18
0
        // 因为是上下文路径,无需返回路径标识
        public static void AddCmdPath <TCmd>(string description, LogEnum logType, Action <TCmd> action, Type location)
            where TCmd : ICmd
        {
            var messagePathId = VirtualRoot.AddMessagePath(description, logType, action, location);

            _contextPathIds.Add(messagePathId);
        }
Example #19
0
 public void SystemLog(LogEnum id = LogEnum.None)
 {
     if (id != LogEnum.None)
     {
         WriteInLogFile(_logs[id].ToString());
     }
 }
Example #20
0
        /// <summary>
        /// 输出日志
        /// </summary>
        /// <param name="em"></param>
        /// <param name="txt"></param>
        public void Log(LogEnum em, string logtxt)
        {
            if (ConfigMgr.GetInstance().V_IsOpenDebugger)
            {
                string txt = string.Format("[{0}]{1} {2}", DateTime.Now.ToLocalTime().ToString(), em.ToString(), logtxt);
                m_lstLog.Add(txt);
                //超过了阀值移除第一条log
                if (m_lstLog.Count >= MAX_LOG_ROW_COUNT)
                {
                    m_lstLog.RemoveAt(0);
                }
                SaveToLocal();
            }
#if UNITY_EDITOR
            switch (em)
            {
            case LogEnum.Warming:
                Debug.LogWarning(logtxt);
                break;

            case LogEnum.Normal:
                Debug.Log(logtxt);
                break;

            case LogEnum.Error:
                Debug.LogError(logtxt);
                break;
            }
#endif
        }
Example #21
0
        public static void AddCmdPath <TCmd>(this Window window, LogEnum logType, Action <TCmd> action, Type location)
            where TCmd : ICmd
        {
            if (WpfUtil.IsInDesignMode)
            {
                return;
            }
            if (window.Resources == null)
            {
                window.Resources = new ResourceDictionary();
            }
            List <IMessagePathId> messagePathIds = (List <IMessagePathId>)window.Resources[messagePathIdsResourceKey];

            if (messagePathIds == null)
            {
                messagePathIds = new List <IMessagePathId>();
                window.Resources.Add(messagePathIdsResourceKey, messagePathIds);
                window.Closed += UiElement_Closed;
            }
            MessageTypeAttribute messageTypeDescription = MessageTypeAttribute.GetMessageTypeAttribute(typeof(TCmd));
            string description   = "处理" + messageTypeDescription.Description;
            var    messagePathId = VirtualRoot.AddMessagePath(description, logType, action, location);

            messagePathIds.Add(messagePathId);
        }
Example #22
0
        static void DebugLog(LogEnum type, char separator, params object[] messages)
        {
#if DEBUG
            var builder = new StringBuilder();
            builder.Append("DEBUG:");
            for (var i = 0; i < messages.Length; i++)
            {
                builder.Append(separator).Append((messages[i] ?? "null").ToString());
            }
            switch (type)
            {
            case LogEnum.Message:
                Debug.Log(builder.ToString());
                break;

            case LogEnum.Warning:
                Debug.LogWarning(builder.ToString());
                break;

            case LogEnum.Error:
                Debug.LogError(builder.ToString());
                break;
            }
#endif
        }
Example #23
0
        public static IMessagePathId BuildCmdPath <TCmd>(Type location, LogEnum logType, Action <TCmd> path)
            where TCmd : ICmd
        {
            MessageTypeAttribute messageTypeDescription = MessageTypeAttribute.GetMessageTypeAttribute(typeof(TCmd));

            return(BuildMessagePath($"处理{messageTypeDescription.Description}命令", logType, location, PathPriority.Normal, path));
        }
Example #24
0
        // 因为是上下文路径,无需返回路径标识
        public static void BuildCmdPath <TCmd>(LogEnum logType, Type location, Action <TCmd> path)
            where TCmd : ICmd
        {
            var messagePathId = VirtualRoot.BuildCmdPath(location, logType, path);

            _contextPathIds.Add(messagePathId);
        }
Example #25
0
        public static IMessagePathId BuildOnecePath <TMessage>(string description, LogEnum logType, Action <TMessage> action, Guid pathId)
        {
            StackTrace ss = new StackTrace(false);
            // 0是CreatePath,1是CreateCmdPath或CreateEventPath,2是当地
            Type location = ss.GetFrame(2).GetMethod().DeclaringType;

            return(MessagePath <TMessage> .Build(MessageDispatcher, location, description, logType, action, pathId, viaLimit : 1));
        }
Example #26
0
        public static void BuildCmdPath <TCmd>(Action <TCmd> path, Type location, LogEnum logType = LogEnum.DevConsole)
            where TCmd : ICmd
        {
            MessageTypeAttribute messageTypeDescription = MessageTypeAttribute.GetMessageTypeAttribute(typeof(TCmd));
            string description = "处理" + messageTypeDescription.Description;

            BuildMessagePath(description, logType, path, location);
        }
Example #27
0
        public void Log(LogEnum type, string text)
        {
            var    repository = new DBMessageRepo();
            string message    = "";

            message = ("[ " + DateTime.Now + " " + type + " ]: " + text);
            repository.AddMessage(message);
        }
Example #28
0
        /// <summary>
        /// 事件响应
        /// </summary>
        public static DelegateHandler <TEvent> On <TEvent>(LogEnum logType, Action <TEvent> action)
            where TEvent : IEvent
        {
            MessageTypeAttribute messageTypeDescription = MessageTypeAttribute.GetMessageTypeDescription(typeof(TEvent));
            string description = "处理" + messageTypeDescription.Description;

            return(Path(description, logType, action));
        }
Example #29
0
        /// <summary>
        /// 命令窗口。使用该方法的代码行应将前两个参数放在第一行以方便vs查找引用时展示出参数信息
        /// </summary>
        public static DelegateHandler <TCmd> Window <TCmd>(LogEnum logType, Action <TCmd> action)
            where TCmd : ICmd
        {
            MessageTypeAttribute messageTypeDescription = MessageTypeAttribute.GetMessageTypeDescription(typeof(TCmd));
            string description = "处理" + messageTypeDescription.Description;

            return(Path(description, logType, action));
        }
Example #30
0
 public HandlerIdViewModel(IHandlerId data)
 {
     _id          = data.Id;
     _messageType = data.MessageType;
     _location    = data.Location;
     _logType     = data.LogType;
     _description = data.Description;
 }
Example #31
0
 /// <summary>
 /// 自定义业务日志
 /// </summary>
 /// <param name="biz">业务标识,如:登录-Login</param>
 /// <param name="_content">内容</param>
 /// <param name="_timeGranularity">时间粒度</param>
 public TextLog(string biz, string _content, TimeGranularity _timeGranularity)
 {
     this.logType         = LogEnum.Customize;
     this.bizSign         = biz;
     this.timeGranularity = _timeGranularity;
     this.content         = _content;
     this.lastWriteTime   = DateTime.Now;
 }
Example #32
0
        public static IMessagePathId BuildCmdPath <TCmd>(Action <TCmd> action, LogEnum logType = LogEnum.DevConsole)
            where TCmd : ICmd
        {
            MessageTypeAttribute messageTypeDescription = MessageTypeAttribute.GetMessageTypeDescription(typeof(TCmd));
            string description = "处理" + messageTypeDescription.Description;

            return(BuildPath(description, logType, action));
        }
Example #33
0
 public static void rewrite(string inputFilePath, string outputFilePath, Func<string, IntegerMap, IntegerMap, string> processor, IntegerMap rowMap = null, IntegerMap colMap = null)
 {
     LogEnum logenum = new LogEnum(inputFilePath);
     StreamWriter writer = File.CreateText(outputFilePath);
     foreach (string line in logenum)
     {
         string outputStr = processor(line, rowMap, colMap);
         writer.WriteLine(outputStr);
     }
     writer.Close();
 }
Example #34
0
File: Util.cs Project: chexia/CF
 public void add(string inputFilePath, int pos)
 {
     LogEnum logenum = new LogEnum(inputFilePath);
     List<double[]> points = new List<double[]>();
     double numEntries = 0;
     foreach(string line in logenum)
     {
         string[] tokens = line.Split(new char[] { '\t' });
         this.add(tokens[pos]);
         numEntries += 1;
     }
 }
Example #35
0
File: Tester.cs Project: chexia/CF
        public static void ABTest(int s, int e, int step, string testPath, string trainPath, string outputPrefix, int rowPos = 1, int colPos = 0, int valPos = -1)
        {
            StreamReader reader = File.OpenText(testPath);
            List<double[]> points = new List<double[]>();

            reader.Close();
            Console.WriteLine("Check 1");
            Matrix testPts = LogProcess.makeUtilMat(932, 528935, testPath, 0, 1);
            Console.WriteLine("check 2");

            for (int req = s; req <= e; req += step)
            {
                reader = File.OpenText(string.Format(trainPath));
                points = new List<double[]>();
                LogEnum logenum = new LogEnum(trainPath);
                int maxRow = 0;
                int maxCol = 0;
                foreach (string line in logenum)
                {
                    string[] tokens = line.Split(new char[] { '\t' });
                    double clicks = 0;
                    double views = 0;
                    if (valPos == -1)
                    {
                        clicks = Double.Parse(tokens[3]);
                        views = Double.Parse(tokens[2]);
                    }
                    if (views < req)
                        continue;
                    maxRow = Math.Max(maxRow, int.Parse(tokens[rowPos]));
                    maxCol = Math.Max(maxCol, int.Parse(tokens[colPos]));
                    points.Add(new double[3] { Double.Parse(tokens[rowPos]), Double.Parse(tokens[colPos]), valPos == -1 ? Math.Min(clicks, views) / views : Double.Parse(tokens[2]) });
                }
                Console.WriteLine("Check 3");
                Matrix utilMat = new Matrix(maxRow + 1, maxCol + 1, points);

                CF filter = new CF(utilMat);
                Console.WriteLine("check 4");
                Tester tester = new Tester(filter, testPts);
                tester.abtest(outputPrefix + "about_" + req + ".txt");
                reader.Close();
            }

            Console.Write("debug: completed AB");
        }
Example #36
0
 public static Matrix makeUtilMat(int rowNum, int colNum, string inputFilePath, int rowPos = 1, int colPos = 0, int valPos = -1)
 {
     List<double[]> points = new List<double[]>();
     LogEnum logenum = new LogEnum(inputFilePath);
     rowNum = colNum = 0;
     foreach (string line in logenum)
     {
         string[] tokens = line.Split(new char[] { '\t' });
         double[] point = new double[3];
         point[0] = Double.Parse(tokens[rowPos]);
         point[1] = Double.Parse(tokens[colPos]);
         if (valPos == -1)
             point[2] = Double.Parse(tokens[3]) / Double.Parse(tokens[2]);
         else
             point[2] = Double.Parse(tokens[valPos]);
         points.Add(point);
         rowNum = Math.Max(rowNum, (int)point[0]);
         colNum = Math.Max(colNum, (int)point[1]);
     }
     Matrix utilMat = new Matrix(rowNum+1, colNum+1, points);//+1 for 0
     return utilMat;
 }
Example #37
0
        public static void Write(LogEnum logEnum, string error = "", Exception exception = null)
        {
            var write = false;
            switch (logEnum) {
                case LogEnum.Warning:
                    write = Settings.LOG_WARNING;
                    break;
                    case LogEnum.Info:
                    write = Settings.LOG_INFO; break;
                case LogEnum.Error:
                    write = Settings.LOG_ERROR; break;
                default:
                    write = true;
                    break;
            } try {
                var pathToLog = Settings.LOG_PATH;
                if (!Directory.Exists(pathToLog))
                    Directory.CreateDirectory(pathToLog); // Создаем директорию, если нужно

                var filename = Path.Combine(pathToLog, string.Format("{0}.log", AppDomain.CurrentDomain.FriendlyName));
                string fullText;
                if (exception != null)
                    fullText = string.Format("[{0:dd.MM.yyy HH:mm:ss.fff}] [{1}.{2}()] {3} : {4}\r\n",
                         DateTime.Now, exception.TargetSite.DeclaringType, exception.TargetSite.Name, error, exception.Message);
                else
                    fullText = string.Format("[{0:dd.MM.yyy HH:mm:ss.fff}] |{1}\t|:{2,5}\r\n",
                        DateTime.Now, logEnum, error);
                if (write || exception != null)
                    lock (sync) {
                        File.AppendAllText(filename, fullText, Encoding.UTF8);
            //                        File.AppendAllText(filename, fullText, Encoding.GetEncoding("Windows-1251"));
                    }
            }
            catch
            {
                // Перехватываем все и ничего не делаем
            }
        }
Example #38
0
 public static void Log(string msg, LogEnum logType, Exception ex = null)
 {
     WriteLog(msg,logType,ex);
 }
Example #39
0
 public void WriteLog(LogEnum name, ILogEntity logEntity)
 {
     WriteLog(name, logEntity.Level, logEntity.GetLogContext());            
 }
Example #40
0
File: IO.cs Project: chexia/CF
        public static void clickPlot(int threshold)
        {
            LogEnum logenum = new LogEnum("train_processed_2.log");
            Dictionary<int, int> click_count = new Dictionary<int, int>();
            StreamWriter writer = new StreamWriter("tmp", false);
            int cnt = 0;
            foreach (string line in logenum)
            {
                string[] tokens = line.Split(new char[] { '\t' });
                double views = double.Parse(tokens[2]);
                if (views < threshold)
                    break;
                if (click_count.ContainsKey(Int32.Parse(tokens[3])))
                    click_count[Int32.Parse(tokens[3])] += 1;
                else
                    click_count.Add(Int32.Parse(tokens[3]), 1);
                cnt += 1;

            }
            Console.WriteLine(cnt);
            foreach (int click in click_count.Keys)
                writer.WriteLine("{0}\t{1}", click, click_count[click]);
            writer.Close();
        }
Example #41
0
File: IO.cs Project: chexia/CF
 public static void manReader(string inputFilePath)
 {
     LogEnum logenum = new LogEnum(inputFilePath);
     foreach (string line in logenum)
     {
         Console.ReadLine();
         Console.WriteLine(line);
     }
 }
Example #42
0
File: IO.cs Project: chexia/CF
 /*
  * Given a log file, and given integerMaps to translate the strings in the log, produce a util matrix
  * */
 public static void reduceTrain(string inputTrain, string inputTest, string outputTrain)
 {
     Matrix testMatrix = LogProcess.makeUtilMat(1000, 100000, inputTest, 0, 1);
     LogEnum logenum = new LogEnum(inputTrain);
     StreamWriter writer = File.CreateText(outputTrain);
     foreach (string line in logenum)
     {
         string[] tokens = line.Split(new char[]{'\t'});
         if (testMatrix.get(Int32.Parse(tokens[0]), Int32.Parse(tokens[1])) != -1)
         {
             Console.WriteLine(line);
             continue;
         }
         writer.WriteLine(line);
     }
     writer.Close();
 }
Example #43
0
File: IO.cs Project: chexia/CF
 public static void split(string inputData, string out_test = "jac_test.log", string out_train = "jac_train.log")
 {
     LogEnum logenum = new LogEnum(inputData);
     Random randgen = new Random();
     StreamWriter testWriter = File.CreateText(out_test);
     StreamWriter trainWriter = File.CreateText(out_train);
     foreach (string line in logenum)
     {
         if (randgen.NextDouble() < 0.3)
             testWriter.WriteLine(line);
         else
             trainWriter.WriteLine(line);
     }
     testWriter.Close();
     trainWriter.Close();
 }
Example #44
0
File: IO.cs Project: chexia/CF
        public static void aggregateBlockTest()
        {
            string inputPath = "C:\\Users\\t-chexia\\Desktop\\blocktest\\blockTestOutput.txt";
            LogEnum logenum = new LogEnum(inputPath);
            foreach (string line in logenum)
            {
                string[] tokens = line.Split(new char[] { '\t' });

            }
        }