• 数据扩样处理


    1.html:

    1  <ul class="search-content">
    2             <li>
    3               <span class="name" (click)="selectorChange('扩样数据', true)">扩样数据</span>
    4             </li>
    5             <li>
    6               <span class="name" (click)="selectorChange('原始数据', false)">原始数据</span>
    7             </li>
    8           </ul>

    1.ts:

    import { CommonService } from './../../service/common.service';
    
     dataType = this.commonService.expandName;
      isShowList: boolean = false;
    
     selectorChange(item, isExpand) {
        if (this.commonService.expand !== isExpand) {
          this.isShowList = false;
          this.commonService.expandName = item;
          this.dataType = item;
          this.commonService.expand = isExpand;
          this.commonService.expandType.next(isExpand);
        }
      }

    common.service.ts:

    import { of, Subject, Subscription } from 'rxjs'; 
    
    expandType = new Subject();
    expand: boolean = true;
    expandName: string = '扩样数据';
    
      // 数据扩样处理
      HandleData(data) {
        if (this.expand) {
          if (typeof data === 'number') {
            //
            data = Math.round((data / 0.73) / 0.9165);
          } else if (!(data instanceof Array)) {
            // 对象
            if (data['subscriberCounts']) {
              data['subscriberCounts'].forEach((item, index) => {
                if (item['countList']) {
                  item['countList'].forEach((item1, index1) => {
                    data['subscriberCounts'][index]['countList'][index1] = Math.round((item1 / 0.73) / 0.9165);
                  });
                }
              });
            } else if (data['countList']) {
              data['countList'].forEach((item, index) => {
                data['countList'][index] = Math.round((item / 0.73) / 0.9165);
              });
            } else if (data['populations']) {
              data['populations'].forEach((item, index) => {
                if (item['countList']) {
                  item['countList'].forEach((item1, index1) => {
                    data['populations'][index]['countList'][index1] = Math.round((item1 / 0.73) / 0.9165);
                  });
                }
              });
            }
          } else {
            // 数组
            data.forEach(item => {
              if (item.subscriberCount) {
                item.subscriberCount = Math.round((item.subscriberCount / 0.73) / 0.9165);
              } else if (item['currentCount']) {
                item.currentCount = Math.round((item.currentCount / 0.73) / 0.9165);
              }else {
                item.populations = Math.round((item.populations / 0.73) / 0.9165);
              }
            });
    
          }
        }
        return data;
      }
  • 相关阅读:
    How do you Design a Circular FIFO Buffer (Queue) in C?

    搞懂分布式技术5:Zookeeper的配置与集群管理实战
    Spring boot 启动提示数据源错误
    IntelliJ IDEA 如何配置数据源
    Windows 10 中你可能用得最多的快捷键
    JUnit 5 测试问题 throws java.lang.Exception’ must be static unless the test class is annotated with @TestInstance(Lifecycle.PER_CLASS)
    Intellij IDEA 如何自动生成 serialVersionUID
    Docsify 初始化文件夹
    Docsify 安装
  • 原文地址:https://www.cnblogs.com/a1-top/p/14047180.html
Copyright © 2020-2023  润新知