YH_EventDataFactory.m 11.8 KB
//
//  YH_EventDataFactory.m
//  YHEventReport
//
//  Created by John Tai on 6/9/2017.
//  Copyright © 2017 YOHO. All rights reserved.
//

#import "YH_EventDataFactory.h"
#import "YHEventReportMacros.h"
#import "NSString+ER_URL.h"
#import "YH_EventUtil.h"

@implementation YH_EventDataFactory

+(NSDictionary *)factoryTimeEventDataWithViewController:(UIViewController *)viewController ElapsedTime:(NSTimeInterval)elapsedTime{
    
    NSString *className = NSStringFromClass([viewController class]);
    NSString *controllerTitle = viewController.navigationItem.title;

    if (IsStrEmpty(className)) {
        return nil;
    }
    
    if (IsStrEmpty(controllerTitle)) {
        controllerTitle=@"";
    }

    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[className er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,[controllerTitle er_encodedString],kYHEventReportTimeTitle,nil];
    
    return dict;
}

+(NSDictionary *)factoryTimeEventDataWithElapsedTime:(NSTimeInterval)elapsedTime  status:(YHEventLoadStatus)status url:(NSString*)url
{
    NSString *currentUrl  = [[NSString alloc]initWithString:url];
    if (IsStrEmpty(currentUrl)) {
        currentUrl=@"";
    }
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[currentUrl er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,@"",kYHEventReportTimeTitle,nil];
    
    return dict;
}

+(NSDictionary *)factoryTimeEventDataWithUIControl:(UIControl *)control url:(NSString*)url ElapsedTime:(NSTimeInterval)elapsedTime{

    NSString *className = NSStringFromClass([control class]);
    
    if (IsStrEmpty(className)) {
        return nil;
    }
 
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[url er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,[className er_encodedString],kYHEventReportTimeTitle,nil];
    
    return dict;
}

+(NSDictionary *)factoryTimeEventDataWithUITableView:(UITableView*)tableView url:(NSString*)url ElapsedTime:(NSTimeInterval)elapsedTime{
    
    NSString *className = NSStringFromClass([tableView class]);
    
    if (IsStrEmpty(className)) {
        return nil;
    }
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[url er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,[className er_encodedString],kYHEventReportTimeTitle,nil];
    
    return dict;
}

+(NSDictionary *)factoryTimeEventDataWithUICollectionView:(UICollectionView*)tableView url:(NSString*)url ElapsedTime:(NSTimeInterval)elapsedTime{
    
    NSString *className = NSStringFromClass([tableView class]);
    
    if (IsStrEmpty(className)) {
        return nil;
    }
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[url er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,[className er_encodedString],kYHEventReportTimeTitle,nil];
    
    return dict;
}

+(NSDictionary *)factoryTimeEventDataWithUIGestureRecognizer:(UITapGestureRecognizer *)gestureRecognizer url:(NSString*)url ElapsedTime:(NSTimeInterval)elapsedTime {
    
    NSString *className = NSStringFromClass([gestureRecognizer class]);
    
    if (IsStrEmpty(className)) {
        return nil;
    }
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[url er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,[className er_encodedString],kYHEventReportTimeTitle,nil];
    
    return dict;
}


+(NSDictionary *)factoryTimeEventDataWithRequestUrl:(NSString*)requestUrl HTTPMethod:(NSString*)method statusCode:(NSString*)statusCode contentLength:(NSString*)length ElapsedTime:(NSTimeInterval)elapsedTime postMethod:(NSString*)postMethod
{
    if (IsStrEmpty(postMethod)) {
        postMethod = @"";
    }
    
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[requestUrl er_encodedString],kYHEventReportTimeURL,[NSString stringWithFormat:@"%.0f",elapsedTime*1000],kYHEventReportTimeElapsed,statusCode,kYHEventReportTimeHttpCode,length,kYHEventReportTimeHttpLength,method,kYHEventReportTimeHttpMethod,postMethod,kYHEventReportTimeHttpEi,nil];
    
    return dict;
}


+(NSString *)getPointName:(YHEventReportPointName)pointName{
    NSString *str = @"";
    switch (pointName) {
        case YHPN_BUSINESS_UFO_SELL:
            str = @"BUSINESS_UFO_SELL";
            break;
        case YHPN_BUSINESS_UFO_BUY:
            str = @"BUSINESS_UFO_BUY";
            break;
        case YHPN_VIEWCONTROLLER:
            str = @"PAGEMETRICS";
            break;
        case YHPH_HTTPMETRICS:
            str = @"HTTPMETRICS";
            break;
        case YHPN_WEBVIEW:
            str = @"WEBVIEW";
            break;
        case YHPN_IMAGEVIEW:
            str = @"IMAGEMETRICS";
            break;
        case YHPN_BUTTON:
            str = @"BUTTON";
            break;
        case YHPN_GESTURERECOGNIZER:
            str = @"GESTURERECOGNIZER";
            break;
        case YHPN_TIMEOUT:
            str = @"TIMEOUT";
            break;
        case YHPN_CODE_ERR:
            str = @"CODE_ERR";
            break;
        case YHPN_H5_FEATURE_META_FAILED:
            str = @"NO_WEBMETA";
            break;
        case YHPN_RN_EXCEPTION:
            str = @"RN_EXCEPTION";
            break;
        case YHPN_CRASH:
            str = @"CRASH";
            break;
        case YHPN_CUSTOM_EXCEPTION:
            str = @"CUSTOM_EXCEPTION";
            break;
        case YHPN_CDN_CHOOSE:
            str = @"CDN_CHOOSE";
            break;
        case YHPN_CDN_ALERT:
            str = @"CDN_ALERT";
            break;
        case YHPN_CDN_BACKHOST:
            str = @"CDN_BACKHOST";
            break;
        case YHPN_CENTER_CHOOSE:
            str = @"CENTER_CHOOSE";
            break;
        case YHPN_APP_PATCHLOAD:
            str = @"APP_PATCHLOAD";
            break;
        case YHPN_RN_PATCHLOAD:
            str = @"RN_PATCHLOAD";
            break;
        case YHPN_START:
            str = @"START";
            break;
        case YHPN_RESUME:
            str = @"RESUME";
            break;
        case YHPN_STOP:
            str = @"STOP";
            break;
        case YHPN_DESTROY:
            str = @"DESTROY";
            break;
        case YHPN_PUSH_ACTIVE:
            str = @"PUSH_ACTIVE";
            break;
        case YHPN_T3_ACTIVE:
            str = @"T3_ACTIVE";
            break;
        case YHPN_UL_ACTIVE:
            str = @"UL_ACTIVE";
            break;
        case YHPN_APP_ACTIVE:
            str = @"APP_ACTIVE";
            break;
        case YHPN_BUSINESS_USER_LOGIN:
            str = @"BUSINESS_USER_LOGIN";
            break;
        case YHPN_BUSINESS_USER_REGIST:
            str = @"BUSINESS_USER_REGIST";
            break;
        case YHPN_BUSINESS_USER_REPASSWORD:
            str = @"BUSINESS_USER_REPASSWORD";
            break;
        case YHPN_BUSINESS_ORDER_ADDSHOPPINGCARD:
            str = @"BUSINESS_ORDER_ADDSHOPPINGCARD";
            break;
        case YHPN_BUSINESS_ORDER_ACCOUNT:
            str = @"BUSINESS_ORDER_ACCOUNT";
            break;
        case YHPN_BUSINESS_ORDER_CONFIRM:
            str = @"BUSINESS_ORDER_CONFIRM";
            break;
        case YHPN_BUSINESS_ORDER_PAY:
            str = @"BUSINESS_ORDER_PAY";
            break;
        case YHPN_BUSINESS_RESPONSE_CHECKSUM:
            str = @"BUSINESS_RESPONSE_CHECKSUM";
            break;
        case YHPN_BUSINESS_UNUSUAL_SERVICE_CODE:
            str = @"BUSINESS_UNUSUAL_SERVICE_CODE";
            break;
        case YHPH_LAG:
            str = @"LAG";
            break;
        case YHPN_NETWORK_API_TIMEOUT:
            str = @"NETWORK_API_TIMEOUT";
            break;
        case YHPN_NETWORK_API_CODE_ERR:
            str = @"NETWORK_API_CODE_ERR";
            break;
        case YHPN_NETWORK_IMAGE_TIMEOUT:
            str = @"NETWORK_IMAGE_TIMEOUT";
            break;
        case YHPN_NETWORK_IMAGE_CODE_ERR:
            str = @"NETWORK_IMAGE_CODE_ERR";
            break;
        case YHPN_NETWORK_API_JSONFORMATFAIL:
            str = @"NETWORK_API_JSONFORMATFAIL";
            break;
        case YHPN_NETWORK_NO_ACTIVENET:
            str = @"NO_ACTIVENET";
            break;
        case YHPN_NETWORK_FIRST_LAUNCH_ERR:
            str = @"NETWORK_FIRST_LAUNCH_ERR";
            break;
        case YHPH_MEMORY:
            str = @"MEMORYMETRICS";
            break;
        case YHPN_AD_UNION:
            str = @"UNION";
            break;
        case YHPN_INFO_APPL:
            str = @"APPL";
            break;
        case YHPN_APPCPU:
            str = @"CPU";
            break;
        case YHPN_APPMEMORY:
            str = @"MEMORY";
            break;
        case YHPN_APPTRAFFIC:
            str = @"TRAFFIC";
            break;
        case YHPN_APPFPS:
            str = @"FPS";
            break;
        case YHPN_BUSINESS_UFO_VIDEO_TRAFFIC:
            str = @"UFO_BUSINESS_VIDEO_TRAFFIC";
            break;
        case YHPN_NETWORK_DETECT:
            str = @"NETWORK_DETECT";
            break;
        default:
            break;
    }
    NSParameterAssert(str.length > 0);
    return str;
}

+(NSString *)getPointType:(YHPointType)pointType{
    NSString *str = @"";
    switch (pointType) {
        case YHPT_NETWORK:
            str = @"NETWORK";
            break;
        case YHPT_EXCEPTION:
            str = @"EXCEPTION";
            break;
        case YHPT_CDN:
            str = @"CDN";
            break;
        case YHPT_CENTER:
            str = @"CENTER";
            break;
        case YHPT_PATCH:
            str = @"PATCH";
            break;
        case YHPT_LIFECYCLE:
            str = @"LIFECYCLE";
            break;
        case YHPT_BUSINESS:
            str = @"BUSINESS";
            break;
        case YHPT_PERFORMANCE:
            str = @"PERFORMANCE";
            break;
        case YHPT_AD:
            str = @"AD";
            break;
        case YHPT_APPTARGET:
            str = @"APPTARGET";
            break;
        case YHPT_UFOBUSINESS:
            str = @"UFO_BUSINESS";
            break;
        case YHPT_INFO:
            str = @"INFO";
            break;
        default:
            break;
    }
    NSParameterAssert(str.length > 0);
    return str;
}

+(NSString *)getDataType:(YHEventReportTrackDataType)type{
    NSString *str = @"";
    
    switch (type) {
        case YHEventReportTrackDataTypeStart:
            str = @"start";
            break;
        case YHEventReportTrackDataTypeDestory:
            str = @"destory";
            break;
        case YHEventReportTrackDataTypeStop:
            str = @"stop";
            break;
        case YHEventReportTrackDataTypeHeartbeat:
            str = @"hb";
            break;
        case YHEventReportTrackDataTypeNONE:
            str = @"realTime";
            break;
        default:
            break;
    }
    
    return str;
}

+(NSDictionary *)getDeviceInfo:(YH_PerformanceAppInfo*)appInfo{
    NSDictionary *deviceInfo = [NSDictionary dictionaryWithObjectsAndKeys:
                                YOHOAppReportDefaultAPPKey,YOHOAppReportKeyAK,
                                IsStrEmpty(appInfo.udid)?@"":appInfo.udid,YOHOAppReportKeyUDID,
                                IsStrEmpty(appInfo.ch)?@"":appInfo.ch,YOHOAppReportKeyCH,
                                IsStrEmpty(appInfo.os)?@"":appInfo.os,YOHOAppReportKeyOS,
                                IsStrEmpty(appInfo.osv)?@"":appInfo.osv,YOHOAppReportKeyOSV,
                                IsStrEmpty(appInfo.dm)?@"":appInfo.dm,YOHOAppReportKeyDM,
//                                IsStrEmpty(appInfo.idfa)?@"":appInfo.idfa,YOHOAppReportKeyIDFA,
                                nil];
    return deviceInfo;
}

@end