精华内容
下载资源
问答
  • Historical footnotes trace the development of the discipline and identify outstanding individual contributions. This book builds the foundation for anyone who needs to learn differential equations ...
  • Historical footnotes trace the development of the discipline and identify outstanding individual contributions. This book builds the foundation for anyone who needs to learn differential equations ...
  • public static void analysisJson (Object objJson, String path, ...student.discipline.categoryCode : 05 student.unit.target : null applyDate : 2018-03-05 cReportName : null
    public static void analysisJson(Object objJson, String path,
                Map<String, String> map) {
            // 如果obj为json数组
            if (objJson instanceof JSONArray) {
                JSONArray objArray = (JSONArray) objJson;
                for (int i = 0; i < objArray.size(); i++) {
                    analysisJson(objArray.get(i), path, map);
                }
            } else if (objJson instanceof JSONObject) {
                JSONObject jsonObject = (JSONObject) objJson;
                Iterator it = jsonObject.keys();
                while (it.hasNext()) {
                    String key = it.next().toString();
                    Object object = jsonObject.get(key);
                    if (path != "" && path != null && !"".equals(path)) {
                        path += "." + key;
                    } else {
                        path += key;
                    }
                    if (object != null && !JSONNull.getInstance().equals(object)) {
                        // 如果得到的是数组
                        if (object instanceof JSONArray) {
                            JSONArray objArray = (JSONArray) object;
                            analysisJson(objArray, path, map);
                            path = modifyPath(path);
                        } else if (object instanceof JSONObject) {
                            analysisJson((JSONObject) object, path, map);
                            path = modifyPath(path);
                        } else {
                            map.put(path, object.toString());
                            // System.out.println("["+path+"]:"+object.toString()+" ");
                            path = modifyPath(path);
    
                        }
                    } else {
                        map.put(path, null);
                        // System.out.println("["+path+"]:"+"null");
                        path = modifyPath(path);
                    }
                }
            }
        }

    测试

    public static void main(String[] args) {
            String data = "[{'id':73,'applyDate':'2018-03-05','reason':'123','auditState':'待审批','editable':false,'student':{'id':1,'sno':'51164500211','name':'张三','nameEn':null,'birthDate':null,'ethnic':{'id':1,'name':'汉族','code':'01'},'gender':{'id':1,'name':'男','code':'1'},'degreeLevel':{'id':1,'name':'硕士研究生','code':'1'},'grade':0,'supervisor':null,'unit':{'id':61,'division':'院系','divisionCode':'01','school':'传播学院','schoolCode':'0123','schoolType':'教学实体','department':'传播学院院部','departmentCode':'012300','departmentType':'教学虚体','since':'2016','until':null,'source':null,'target':null},'discipline':{'id':148,'category':'文学','categoryCode':'05','major':'中国语言文学','majorCode':'0501','minor':'文艺学','minorCode':'050101','originCode':'','degreeLevel':'12','degreeType':'1','area':'p','nature':'gjbzk','since':'2016','until':null,'source':null,'target':null}},'staff':null,'type':{'major':'休学','majorCode':2,'minor':'休学','minorCode':1},'fileNames':[],'applicantUserName':'admin','applicantName':'超级管理员','cTerm':'1','cEarlyGraduationTerm':null,'cStaff':null,'cTransmitDate':null,'cCategory':null,'cMajor':null,'cMinor':null,'cDepartmentCode':null,'cSchoolCode':null,'cReportId':null,'cReportName':null,'cReportLink':null,'cReportDigest':null}]";
            System.out.println(data);
            JSONObject jsonData = JSONObject.fromObject(data.substring(1,
                    data.length() - 1));
            Map<String, String> resMap = new HashMap<String, String>();
            analysisJson(jsonData, "", resMap);
            System.out.println();
            for (String str : resMap.keySet()) {
                System.out.println(str + ": " + resMap.get(str));
            }
        }

    print

    student.unit.schoolType: 教学实体
    student.discipline.until: null
    reason: 123
    student.sno: 51164500211
    student.ethnic.name: 汉族
    student.unit.until: null
    cStaff: null
    student.unit.id: 61
    student.discipline.target: null
    student.birthDate: null
    student.unit.since: 2016
    student.unit.source: null
    student.gender.id: 1
    cEarlyGraduationTerm: null
    student.discipline.since: 2016
    id: 73
    student.gender.code: 1
    type.major: 休学
    student.degreeLevel.id: 1
    type.minor: 休学
    student.nameEn: null
    applicantName: 超级管理员
    cReportDigest: null
    cReportId: null
    student.unit.divisionCode: 01
    student.discipline.major: 中国语言文学
    student.discipline.source: null
    student.gender.name: 
    student.unit.school: 传播学院
    student.unit.departmentType: 教学虚体
    student.discipline.majorCode: 0501
    type.majorCode: 2
    student.unit.departmentCode: 012300
    student.ethnic.id: 1
    type.minorCode: 1
    applicantUserName: admin
    student.unit.department: 传播学院院部
    student.discipline.degreeLevel: 12
    cSchoolCode: null
    student.unit.schoolCode: 0123
    student.discipline.minor: 文艺学
    student.discipline.id: 148
    student.discipline.degreeType: 1
    cMajor: null
    cMinor: null
    cReportLink: null
    student.degreeLevel.code: 1
    auditState: 待审批
    student.discipline.minorCode: 050101
    student.degreeLevel.name: 硕士研究生
    cCategory: null
    student.unit.division: 院系
    student.discipline.category: 文学
    student.id: 1
    cDepartmentCode: null
    student.grade: 0
    student.discipline.area: p
    student.supervisor: null
    student.discipline.nature: gjbzk
    editable: false
    cTransmitDate: null
    staff: null
    student.name: 张三
    cTerm: 1
    student.ethnic.code: 01
    student.discipline.originCode: 
    student.discipline.categoryCode: 05
    student.unit.target: null
    applyDate: 2018-03-05
    cReportName: null
    
    展开全文
  • This command attaches queue discipline HTB to eth0 and gives it the "handle" 1: . This is just a name or identifier with which to refer to it below. The default 12 means that any traffic that is not...

    1. Introduction

    HTB is meant as a more understandable, intuitive and faster replacement for the CBQ qdisc in Linux. Both CBQ and HTB help you to control the use of the outbound bandwidth on a given link. Both allow you to use one physical link to simulate several slower links and to send different kinds of traffic on different simulated links.如何分流 In both cases, you have to specify how to divide the physical link into simulated links and how to decide which simulated link to use for a given packet to be sent.

    This document shows you how to use HTB. Most sections have examples, charts (with measured data) and discussion of particular problems.

    This release of HTB should be also much more scalable. See comparison at HTB home page.

    Please read: tc tool (not only HTB) uses shortcuts to denote units of rate. kbps means kilobytes and kbit means kilobits ! This is the most FAQ about tc in linux.

    2. Link sharing

    Ag2Leaf3flat.gifProblem: We have two customers, A and B, both connected to the internet via eth0. We want to allocate 60 kbps to B and 40 kbps to A. Next we want to subdivide A's bandwidth 30kbps for WWW and 10kbps for everything else. Any unused bandwidth can be used by any class which needs it (in proportion of its allocated share).

    HTB ensures that the amount of service provided to each class is at least the minimum of the amount it requests and the amount assigned to it. When a class requests less than the amount assigned, the remaining (excess) bandwidth is distributed to other classes which request service. 保证流量,多余的给其他人用

    Also see document about HTB internals - it describes goal above in greater details.

    Note: In the literature this is called "borrowing" the excess bandwidth. We use that term below to conform with the literature. We mention, however, that this seems like a bad term since there is no obligation to repay the resource that was "borrowed".

    The different kinds of traffic above are represented by classes in HTB. The simplest approach is shown in the picture at the right.
    Let's see what commands to use:

    
      This command attaches queue discipline HTB to eth0 and gives it the "handle" 1:. This is just a name or identifier with which to refer to it below. The default 12 means that any traffic that is not otherwise classified will be assigned to class 1:12.  
     

    Note: In general (not just for HTB but for all qdiscs and classes in tc), handles are written x:y where x is an integer identifying a qdisc and y is an integer identifying a class belonging to that qdisc. The handle for a qdisc must have zero for its y value and the handle for a class must have a non-zero value for its y value. The "1:" above is treated as "1:0".

    
      
     

    The first line creates a "root" class, 1:1 under the qdisc 1:. The definition of a root class is one with the htb qdisc as its parent. A root class, like other classes under an htb qdisc allows its children to borrow from each other, but one root class cannot borrow from another. We could have created the other three classes directly under the htb qdisc, but then the excess bandwidth from one would not be available to the others. In this case we do want to allow borrowing, so we have to create an extra class to serve as the root and put the classes that will carry the real data under that. These are defined by the next three lines. The ceil parameter is described below.

    同一个root class下的子类可以相互借流量,如果直接不在qdisc下面创建一个root,而是直接创建三个class,他们之间是不能相互借流量的。

    Note: Sometimes people ask me why they have to repeat dev eth0 when they have already used handle or parent. The reason is that handles are local to an interface, e.g., eth0 and eth1 could each have classes with handle 1:1.

    We also have to describe which packets belong in which class. This is really not related to the HTB qdisc. See the tc filter documentation for details. The commands will look something like this:

    
      (We identify A by its IP address which we imagine here to be 1.2.3.4.)  
     

    Note: The U32 classifier has an undocumented design bug which causes duplicate entries to be listed by "tc filter show" when you use U32 classifiers with different prio values. flatnp.gif

    You may notice that we didn't create a filter for the 1:12 class. It might be more clear to do so, but this illustrates the use of the default. Any packet not classified by the two rules above (any packet not from source address 1.2.3.4) will be put in class 1:12.

    Now we can optionally attach queuing disciplines to the leaf classes. If none is specified the default is pfifo.

    
      That's all the commands we need. Let's see what happens if we send packets of each class at 90kbps and then stop sending packets of one class at a time. Along the bottom of the graph are annotations like "0:90k". The horizontal position at the center of the label (in this case near the 9, also marked with a red "1") indicates the time at which the rate of some traffic class changes. Before the colon is an identifier for the class (0 for class 1:10, 1 for class 1:11, 2 for class 1:12) and after the colon is the new rate starting at the time where the annotation appears. For example, the rate of class 0 is changed to 90k at time 0, 0 (= 0k) at time 3, and back to 90k at time 6.  
     

    Initially all classes generate 90kb. Since this is higher than any of the rates specified, each class is limited to its specified rate. At time 3 when we stop sending class 0 packets, the rate allocated to class 0 is reallocated to the other two classes in proportion to their allocations, 1 part class 1 to 6 parts class 2. (The increase in class 1 is hard to see because it's only 4 kbps.) Similarly at time 9 when class 1 traffic stops its bandwidth is reallocated to the other two (and the increase in class 0 is similarly hard to see.) At time 15 it's easier to see that the allocation to class 2 is divided 3 parts for class 0 to 1 part for class 1. At time 18 both class 1 and class 2 stop so class 0 gets all 90 kbps it requests.

    如图,时间0的时候,0,1,2都以90k的速度发送数据,在时间3的时候,将0的发送停止,红色的线归零,剩余的流量按照比例分给了蓝色的和绿色的线。

    在时间6的时候,将0的发送重启为90k,则蓝色和绿色的流量返还给红色的流量。

    在时间9的时候,将1的发送停止,绿色的流量为零,剩余的流量按照比例分给了蓝色和红色。在时间12,将1的发送恢复,红色和蓝色返还流量。

    在时间15,将2的发送停止,蓝色流量为零,剩余的流量按照比例分给红色和绿色。

    在时间19,将1的发送停止,绿色的流量为零,所有的流量都归了红色。

    It might be good time to touch concept of quantums now. In fact when more classes want to borrow bandwidth they are each given some number of bytes before serving other competing class. This number is called quantum. You should see that if several classes are competing for parent's bandwidth then they get it in proportion of their quantums. It is important to know that for precise operation quantums need to be as small as possible and larger than MTU.
    Normaly you don't need to specify quantums manualy as HTB chooses precomputed values. It computes classe's quantum (when you add or change it) as its rate divided by r2q global parameter. Its default value is 10 and because typical MTU is 1500 the default is good for rates from 15 kBps (120 kbit). For smaller minimal rates specify r2q 1 when creating qdisc - it is good from 12 kbit which should be enough. If you will need you can specify quantum manualy when adding or changing the class. You can avoid warnings in log if precomputed value would be bad. When you specify quantum on command line the r2q is ignored for that class.

    This might seem like a good solution if A and B were not different customers. However, if A is paying for 40kbps then he would probably prefer his unused WWW bandwidth to go to his own other service rather than to B. This requirement is represented in HTB by the class hierarchy. Ag2Leaf3hier.gif

    3. Sharing hierarchy

    The problem from the previous chapter is solved by the class hierarchy in this picture. Customer A is now explicitly represented by its own class. Recall from above that the amount of service provided to each class is at least the minimum of the amount it requests and the amount assigned to it. This applies to htb classes that are not parents of other htb classes. We call these leaf classes. For htb classes that are parents of other htb classes, which we call interior classes, the rule is that the amount of service is at least the minumum of the amount assigned to it and the sum of the amount requested by its children. In this case we assign 40kbps to customer A. That means that if A requests less than the allocated rate for WWW, the excess will be used for A's other traffic (if there is demand for it), at least until the sum is 40kbps.

    对于叶子节点,保证的流量为=min(request, assigned)

    对于中间节点,保证的流量为=min(assigned, sum(request of children))

    Notes: Packet classification rules can assign to inner nodes too. Then you have to attach other filter list to inner node. Finally you should reach leaf or special 1:0 class. The rate supplied for a parent should be the sum of the rates of its children.

    The commands are now as follows:

     
     hiernp.gif 
     

    We now turn to the graph showing the results of the hierarchical solution. When A's WWW traffic stops, its assigned bandwidth is reallocated to A's other traffic so that A's total bandwidth is still the assigned 40kbps.
    If A were to request less than 40kbs in total then the excess would be given to B.

    4. Rate ceiling

    The ceil argument specifies the maximum bandwidth that a class can use. This limits how much bandwidth that class can borrow. The default ceil is the same as the rate. (That's why we had to specify it in the examples above to show borrowing.) We now change the ceil 100kbps for classes 1:2 (A) and 1:11 (A's other) from the previous chapter to ceil 60kbps and ceil 20kbps.

    The graph at right differs from the previous one at time 3 (when WWW traffic stops) because A/other is limited to 20kbps. Therefore customer A gets only 20kbps in total and the unused 20kbps is allocated to B.
    The second difference is at time 15 when B stops. Without the ceil, all of its bandwidth was given to A, but now A is only allowed to use 60kbps, so the remaining 40kbps goes unused. 

    hiernpceil.gif

    This feature should be useful for ISPs because they probably want to limit the amount of service a given customer gets even when other customers are not requesting service. (ISPs probably want customers to pay more money for better service.) Note that root classes are not allowed to borrow, so there's really no point in specifying a ceil for them.

    Notes: The ceil for a class should always be at least as high as the rate. Also, the ceil for a class should always be at least as high as the ceil of any of its children.

    5. Burst

    Networking hardware can only send one packet at a time and only at a hardware dependent rate. Link sharing software can only use this ability to approximate the effects of multiple links running at different (lower) speeds. Therefore the rate and ceil are not really instantaneous measures but averages over the time that it takes to send many packets. What really happens is that the traffic from one class is sent a few packets at a time at the maximum speed and then other classes are served for a while. The burst and cburst parameters control the amount of data that can be sent at the maximum (hardware) speed without trying to serve another class.

    虽然逻辑上是分Class的,但是对于硬件来讲,包是依次发送的。

    事实发生的事情是一个Class中的包被尽快的发送一段时间,然后切换到另一个Class。

     

    If cburst is smaller (ideally one packet size) it shapes bursts to not exceed ceil rate in the same way as TBF's peakrate does.

    When you set burst for parent class smaller than for some child then you should expect the parent class to get stuck sometimes (because child will drain more than parent can handle). HTB will remember these negative bursts up to 1 minute.

    You can ask why I want bursts. Well it is cheap and simple way how to improve response times on congested link. For example www traffic is bursty. You ask for page, get it in burst and then read it. During that idle period burst will "charge" again.

    Note: The burst and cburst of a class should always be at least as high as that of any of it children.

    hiernpburst.gif 

    On graph you can see case from previous chapter where I changed burst for red and yellow (agency A) class to 20kb but cburst remained default (cca 2 kb).
    Green hill is at time 13 due to burst setting on SMTP class. A class. It has underlimit since time 9 and accumulated 20 kb of burst. The hill is high up to 20 kbps (limited by ceil because it has cburst near packet size).
    Clever reader can think why there is not red and yellow hill at time 7. It is because yellow is already at ceil limit so it has no space for furtner bursts.
    There is at least one unwanted artifact - magenta crater at time 4. It is because I intentionaly "forgot" to add burst to root link (1:1) class. It remembered hill from time 1 and when at time 4 blue class wanted to borrow yellow's rate it denied it and compensated itself.

    Limitation: when you operate with high rates on computer with low resolution timer you need some minimal burst and cburst to be set for all classes. Timer resolution on i386 systems is 10ms and 1ms on Alphas. The minimal burst can be computed as max_rate*timer_resolution. So that for 10Mbit on plain i386 you needs burst 12kb.

    If you set too small burst you will encounter smaller rate than you set. Latest tc tool will compute and set the smallest possible burst when it is not specified.

    hierprio.gif

    6. Priorizing bandwidth share

    Priorizing traffic has two sides. First it affects how the excess bandwidth is distributed among siblings. Up to now we have seen that excess bandwidth was distibuted according to rate ratios. Now I used basic configuration from chapter 3 (hierarchy without ceiling and bursts) and changed priority of all classes to 1 except SMTP (green) which I set to 0 (higher).
    From sharing view you see that the class got all the excess bandwidth. The rule is that classes with higher priority are offered excess bandwidth first. But rules about guaranted rate and ceil are still met.

    There is also second face of problem. It is total delay of packet. It is relatively hard to measure on ethernet which is too fast (delay is so neligible). But there is simple help. We can add simple HTB with one class rate limiting to less then 100 kbps and add second HTB (the one we are measuring) as child. Then we can simulate slower link with larger delays.
    For simplicity sake I use simple two class scenario:

    
      
     

    priotime.gif

     Note: HTB as child of another HTB is NOT the same as class under another class within the same HTB. It is because when class in HTB can send it will send as soon as hardware equipment can. So that delay of underlimit class is limited only by equipment and not by ancestors.
    In HTB under HTB case the outer HTB simulates new hardware equipment with all consequences (larger delay)

    Simulator is set to generate 50 kbps for both classes and at time 3s it executes command:

    
      As you see the delay of WWW class dropped nearly to the zero while SMTP's delay increased. When you priorize to get better delay it always makes other class delays worse. 
    Later (time 7s) the simulator starts to generate WWW at 60 kbps and SMTP at 40 kbps. There you can observe next interesting behaviour. When class is overlimit (WWW) then HTB priorizes underlimit part of bandwidth first.

    What class should you priorize ? Generaly those classes where you really need low delays. The example could be video or audio traffic (and you will really need to use correct rate here to prevent traffic to kill other ones) or interactive (telnet, SSH) traffic which is bursty in nature and will not negatively affect other flows.
    Common trick is to priorize ICMP to get nice ping delays even on fully utilized links (but from technical point of view it is not what you want when measuring connectivity).

    7. Understanding statistics

    The tc tool allows you to gather statistics of queuing disciplines in Linux. Unfortunately statistic results are not explained by authors so that you often can't use them. Here I try to help you to understand HTB's stats.
    First whole HTB stats. The snippet bellow is taken during simulation from chapter 3.
    
      First three disciplines are HTB's children. Let's ignore them as PFIFO stats are self explanatory. 
    overlimits tells you how many times the discipline delayed a packet. direct_packets_stat tells you how many packets was sent thru direct queue. Other stats are sefl explanatory. Let's look at class' stats:
    
      I deleted 1:11 and 1:12 class to make output shorter. As you see there are parameters we set. Also there are level and DRR quantum informations. 
    overlimits shows how many times class was asked to send packet but he can't due to rate/ceil constraints (currently counted for leaves only).
    rate, pps tells you actual (10 sec averaged) rate going thru class. It is the same rate as used by gating.
    lended is # of packets donated by this class (from its rate) and borrowed are packets for whose we borrowed from parent. Lends are always computed class-local while borrows are transitive (when 1:10 borrows from 1:2 which in turn borrows from 1:1 both 1:10 and 1:2 borrow counters are incremented).
    giants is number of packets larger than mtu set in tc command. HTB will work with these but rates will not be accurate at all. Add mtu to your tc (defaults to 1600 bytes).

    8. Making, debugging and sending error reports

    If you have kernel 2.4.20 or newer you don't need to patch it - all is in vanilla tarball. The only thing you need is tc tool. Download HTB 3.6 tarball and use tc from it.

    You have to patch to make it work with older kernels. Download kernel source and use patch -p1 -i htb3_2.X.X.diff to apply the patch. Then use make menuconfig;make bzImage as before. Don't forget to enable QoS and HTB.
    Also you will have to use patched tc tool. The patch is also in downloads or you can download precompiled binary.

    If you think that you found an error I will appreciate error report. For oopses I need ksymoops output. For weird qdisc behaviour add parameter debug 3333333 to your tc qdisc add .... htb. It will log many megabytes to syslog facility kern level debug. You will probably want to add line like:
    kern.debug -/var/log/debug
    to your /etc/syslog.conf. Then bzip and send me the log via email (up to 10MB after bzipping) along with description of problem and its time.

    转载于:https://www.cnblogs.com/popsuper1982/p/3800533.html

    展开全文
  • P122, 这是IQR method课的第一次作业,需要统计检验,x和y是否显著的有线性关系。 Assignment 1 1) Find a small bivariate...own discipline) and produce a scatterplot (this is easy using any spreadsheet...

    P122, 这是IQR method课的第一次作业,需要统计检验,x和y是否显著的有线性关系。

    Assignment 1
    1) Find a small bivariate dataset (preferably from your
    own discipline) and produce a scatterplot (this is easy
    using any spreadsheet)
    2) Use any statistics tool (a calculator, spreadsheet or
    statistical package) to calculate the best fitting
    regression line and test whether the population slope
    (=B) is zero.
    Notes:
    1. Testing whether the population slope (=B) is zero is
    different to whether the estimated slope (=b) is zero.
    2. Instructions for loading and using the Analysis
    Toolpak in Excel: <https://support.office.com/en-us/article/load-theanalysis-
    toolpak-in-excel-6a63e598-cd6d-42e3-9317-6b40ba1a66b4>
    

     

    入门:散点图、线性拟合、拟合参数slope

    进阶:统计检验,多重矫正FDR

    基本概念:

     这和基本的代数一样,只是统计更加严谨,把误差纳入到模型中了。

    怎么估计A和B呢?

    A和B可以看做是群体的参数,a和b可以看做是样本的估计参数,我们的方法是通过使残差最小来估计出a和b。

    如果我们假设误差项服从正态分布,那么我们就可以对slope斜率进行统计推断。

    我们可以构造出一个关于b的统计量,它会服从t分布。

    这部分还是看耶鲁大学的教程吧:Inference in Linear Regression

    如果只是应用的话,知道怎么用R求显著性就行了。

     

    入门R代码

    height <- c(176, 154, 138, 196, 132, 176, 181, 169, 150, 175)
    bodymass <- c(82, 49, 53, 112, 47, 69, 77, 71, 62, 78)
    plot(bodymass, height)
    plot(bodymass, height, pch = 16, cex = 1.3, col = "blue", main = "HEIGHT PLOTTED AGAINST BODY MASS", xlab = "BODY MASS (kg)", ylab = "HEIGHT (cm)")
    

    进阶

    eruption.lm = lm(eruptions ~ waiting, data=faithful)
    summary(eruption.lm) 
    help(summary.lm)
    
    Call: 
    lm(formula = eruptions ~ waiting, data = faithful) 
     
    Residuals: 
        Min      1Q  Median      3Q     Max 
    -1.2992 -0.3769  0.0351  0.3491  1.1933 
     
    Coefficients: 
                Estimate Std. Error t value Pr(>|t|) 
    (Intercept) -1.87402    0.16014   -11.7   <2e-16 *** 
    waiting      0.07563    0.00222    34.1   <2e-16 *** 
    --- 
    Signif. codes:  0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 
     
    Residual standard error: 0.497 on 270 degrees of freedom 
    Multiple R-squared: 0.811,      Adjusted R-squared: 0.811 
    F-statistic: 1.16e+03 on 1 and 270 DF,  p-value: <2e-16
    

    Decide whether there is a significant relationship between the variables in the linear regression model of the data set faithful at .05 significance level.

    NULL hypothesis: no relationship between x and y, so the slope is zero.

    假设误差服从正态分布,基于零假设,我们要检验以下统计量是否显著。

    统计量:(b-B)/sb follows a Student’s t distribution with n-2 degrees of freedom, where sb=s/√(∑(X-Mean(X))2) is the standard error of b. 

     


    进阶:多项回归,多重检验

    多次回归以后专门开一贴,以下讲多重检验multiple testing。

    Lecture 10: Multiple Testing - PPT通俗易懂

    所有的问题都是围绕着多重和error(就是一个2X2的表,根据检验和真实,有四种可能)的:

    做一次检验,我们犯第一类错误(应该是真的,我们拒绝了,又叫错误拒绝率)为a,犯第二类错误(应该是假的,我们接受了,又叫纳伪率)为b。

    那么,我们做基因差异表达,对每一个基因做一次检验,有3万多个基因,我们至少犯1次第一类错误的概率是多少呢?1-(a)2 

    为了使我们整体犯第一类错的概率效率0.05,我们必须要进行多重矫正。

    方法1:

    Bonferroni,直接把a 0.05除以次数,比如1万,来设立显著性阈值,这样会极大地增大第二类错误,我们会漏掉大量有用的信息。

    方法2:

    FDR,就是错误发现率,假/真阳性比例,就是显著水平里的真显著和假显著的比例。千万不要和假阳性率搞混了。

    做法很简答,把我们检测出来的显著的结果按p-value排列一下,去掉后面5%不太显著的结果。FDR的计算方法很多,BH最为常用。

     

    最熟悉的例子就是:生物信息学里的GO富集分析,一次检验是指我们的gene list与一个GO term做超几何分布检验,然而GO terms那么多,我们必须矫正,以控制错误率。

    另一个就是一鸣的组会讲的回归问题的拟合,我们拟合了很多次,需要对p-value做矫正,看PPT。

     


     

    medium专题

    这个非常值得一看,回归里的系数和p-value分别是什么含义。

    How to Interpret Regression Analysis Results: P-values and Coefficients

    null hypothesis:coefficient is 0,如果p-value小于0.05,我们就可以拒绝零假设。

     

    multiple testing

    Benjamini and Hochberg's method

    aggregated FDR

    FDR with group info


    Hu, James X., Hongyu Zhao, and Harrison H. Zhou. "False discovery rate control with groups." Journal of the American Statistical Association 105.491 (2010): 1215-1227.

     

    pak说:这个太重要了,对于大数据时代的统计而言。

    一般情况下:我们可以认为Q value = FDR = adjusted p value,即三者是一个东西,虽然有些定义上的细微区别,但是问题也不大。

     

    参考:浅谈多重检验校正FDR

     

    待续~

     

    转载于:https://www.cnblogs.com/leezx/p/9121312.html

    展开全文
  • JS_Detail和Discipline

    2014-03-31 20:31:00
    Name:BAIDUID,Value:557D96D13E7C9662F7DCFD9E8C13FED1:FG Name: BDRCVFR[DfWFxj3YnYn],Value:mk3SLVN4HKm Name: CNZZDATA30080359,Value:cnzz_eid%3D2026158897-1392476638-http%253A%252F%252F ...

    编码原则

    Js控件代码3部曲

     

    (1)设置元素的 状态 在onready中添加

    (2)设置元素的 动作, 每个动作 封装成 function(enclosure)

    (3)remove load之前 删除方法,属性

     

    DeferList1次和 3次DeferList    14s  vs  29s

    1次:

    var tempAr=[];

          var queryTask=new esri.tasks.QueryTask(getQueryUrl(0));//station

          var query=new esri.tasks.Query();

          query.outSpatialReference=mapAppObj.map.spatialReference;

          query.outFields=["*"];

          query.returnGeometry=true

          query.where="isFinished=1";

         

          tempAr.push(queryTask.execute(query));

          queryTask=new esri.tasks.QueryTask(getQueryUrl(1));//line

          tempAr.push(queryTask.execute(query));

          queryTask=new esri.tasks.QueryTask(getQueryUrl(2));//sections

          tempAr.push(queryTask.execute(query));     

          var deferList=new dojo.DeferredList(tempAr);

          deferList.then(function(results){      

     

    时间:   

     

     

     

     

     

     

     

     

    4次:

    initStationFeatures()

    initSectionFeatures()

    initLineFeatures()

    时间:

     

     

    引用类型, 指向变量控制在1

    举例:

       var arr=[obj,obj2,obj3,obj4]

       var newArr=[];

       for(var i=0;i<=arr.length-1;i++){

                  if(…){

           newArr.push(arr[i])

    }

    }

           Return newArr

    Obj:  arr[0],newArr[0],指向。

    这样性能低于  arr[0]

     

    引用类型 军规 让指向变量只有一个,

     

    Case1:

    newFeatures 和features都指向 features

       var newFeatures=[];//仅入 京之区

             for(var i=0;i<=features.length-1;i++){       

                var oneFeature=features[i];

                var name=oneFeature.attributes.NAME;

     

    时间:523ms

     

     

     

    case2:

    只有features

    for(var i=0;i<=features.length-1;i++){           

                var oneFeature=features[i];

                var name=oneFeature.attributes.NAME;

                //Yellow       

                if(name=="昌平区"||name=="丰台区"){

                   oneFeature.setSymbol(new   

                   oneFeature.setInfoTemplate(null);

                   targetLayer.add(oneFeature);

                }

     

     

     

     

    时间:219ms

     

     

     

     

    2M到4M 和 2s到4s

    若不会耗尽客户端的内存。用空间换时间。

     

     

    动态的部分越少越好

          

    Iframe越少越好

    原因:iframe导致内存泄露.

     

    click军规-禁止在代码中触发事件

      事件金留给用户处理

    函数三部曲

    --1检查异常值

    --2执行运算

    --3返回结果

     

    页面两部曲

    --1.编写HTML

    --2. documentReady中请求数据

    --3.documentReady中绑定事件

    代码检查F12

    探查器->开始采样->调用树

     

    说明:计数,执行次数

    包含时间,每次执行的毫秒数

     

    代码不好改,是因为不自然

    不要在HTML中onclick

     原因:1不好维护

           2 副作用很多

     

    300*300 table显示 性能要义:

    (1)   不要在td中加div

    (2)   一次把300*300的html写好后,再添加到dom元素中。(只用一次append()或html())

    (3)   尽量不要给td设置id,id个数90000时,对性能影响很大.

     

     

    多进程控制

    多个异步进程,如何同步

     

    //总结:第一个异步请求发出前blockUI。 Sentinal++; 每个接收函数中将

    Sentinal--,并判断sentinal是否是0;如果是,解除block。执行后续操作。

     

    var hangCount=0;

    function blockMap(){

       $.blockUI({

          message : '<h1><img src="../img/common/busy.gif"></img>&nbsp;地图加载中…</h1>'

       });

    };

    function unBlockMap(){

       $.unblockUI();

    }

    //递减sentinal,如果接收数据完毕,则解除block

    function minusCheckHangZero(){

       if(hangCount==0){

          unBlockMap();

          return;

       }

       hangCount--;

       if(hangCount==0){

          unBlockMap();

          return;

       }

    };

    $(document).ready(function(){    

       console.log("map.html ready() is triggered");

       mapAppObj=new mapObject(); 

       mapAppObj.initBaseMap();

      

       blockMap();

       //进程1

       hangCount++;

       mapAppObj.featuresDictionary.getLinesInOd();//获取OD中所有line

       //进程2

       hangCount++;

       mapAppObj.featuresDictionary.getStationsInOd();//获取OD中所有Station 

       //进程3

       hangCount++;

       mapAppObj.featuresDictionary.getAllFeatures(function(){      

          mapAppObj.lineLayer.init();//依赖进程3

          mapAppObj.stationLayer.init(false);//依赖进程3

          minusCheckHangZero();   

       });//callback end

      

       //进程4  

       mapAppObj.labelLayer.addToMap(); 

    });

     

     

    数据加载前,必须BlockUI

     

     

    setInterval和setTimeout

    闪烁效果

    $(function(){  

       var bIn=setInterval(function(){

             if($("#dv").hasClass("dNone")){

                $("#dv").removeClass("dNone");

             }

             else{

                $("#dv").addClass("dNone");

             }

          },300);

       setTimeout(function(){

          clearInterval(bIn);

       },2000);

    });

     

     

    Confirm Alert Prompt

    (1)var flag=confirm(“确定离开此页面”);

    (2)alert(“未能获取数据”);

    (3)

    var str=prompt(“请输入工程师姓名”,”姓名”);

     

     

     

     

    Window_Anchor对象

    新建选项卡

    <a class="div1ADetail" href="'+onePoi.detailUrl+'" target="_blank">详情>></a>

     

     

    备注:去掉下划线 text-decoration:none

     

    伪造新建选项卡

              var $a=$('<a href="http://www.baidu.com" target="_blank"></a>');

             $a.appendTo("body");

             $a[0].click();

             $a.remove();

     

     

     

     

    Location对象_路径符号

    获取网站根目录

    //获取根目录名  /odGIS

    function getRootName(){

       var path = document.location.pathname.substr(1);

       path = "/" + path.substr(0, path.indexOf("/"));

       return path;

    }

     

    /到端口号;./当前页的父目录;../当前目录向上


    Cookie对象

    遍历cookies

    客户端:所有cookies存储在document.cookie中。

            格式:co1=val1;col2=val2;col3=val3;

    摘要:

    取所有cookies

    document.cookie

     

     

     

     

     

    function loopCookies(){

        var cosStr=document.cookie;

        if(cosStr==""){

           console.log("no cookie exist");

           return;

        }

        var cos=document.cookie.split(";");

        

        for(var i=0;i<=cos.length-1;i++){

           var cN=cos[i].split("=")[0];

           var cV=cos[i].split("=")[1];

           console.log("Name:"+cN+",Value:"+cV+"\n");

        }

     }

     

    在baidu上执行效果:

    Name:BAIDUID,Value:557D96D13E7C9662F7DCFD9E8C13FED1:FG

    Name: BDRCVFR[DfWFxj3YnYn],Value:mk3SLVN4HKm

    Name: CNZZDATA30080359,Value:cnzz_eid%3D2026158897-1392476638-http%253A%252F%252Fwww.baidu.com%252F%26ntime%3D1392859028%26cnzz_a%3D9%26sin%3Dnone%26ltime%3D1392852635349%26rtime%3D6

    Name: BDRCVFR[feWj1Vr5u3D],Value:I67x6TjHwwYf0

    Name: BD_CK_SAM,Value:1

    Name: H_PS_PSSID,Value:5095_1447_5213_4264_4760_5244_5188

     

     

     

     

     

     

    创建cookie

    //源自w3school
    http://www.w3school.com.cn/js/js_cookies.asp
     
    创建cookie
    function setCookie(c_name,value,expiredays)
    {
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
    }
     
    获取cookie
    function getCookie(c_name)
    {
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=")
      if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1 
        c_end=document.cookie.indexOf(";",c_start)
        if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
        } 
      }
    return ""
    }

     

     

     

     

     

     

    String 对象

    字符串包含

    1. var Cts = "bblText";  
    2.   
    3. if(Cts.indexOf("Text") >= 0 )  
    4. {  
    5.     alert('Cts中包含Text字符串');  
    6. }  

     

    JSON和字符串互相转换

     

    Json转 字符串:var last= JSON.stringify(obj)

    字符串转Json:   JSON.parse(string)

     


    String Object Methods

    Method

    Description

    charAt()

    Returns the character at the specified index

    charCodeAt()

    Returns the Unicode of the character at the specified index

    concat()

    Joins two or more strings, and returns a copy of the joined strings

    fromCharCode()

    Converts Unicode values to characters

    indexOf()

    Returns the position of the first found occurrence of a specified value in a string

    lastIndexOf()

    Returns the position of the last found occurrence of a specified value in a string

    localeCompare()

    Compares two strings in the current locale

    match()

    Searches for a match between a regular expression and a string, and returns the matches

    replace()

    Searches for a match between a substring (or regular expression) and a string, and replaces the matched substring with a new substring

    search()

    Searches for a match between a regular expression and a string, and returns the position of the match

    slice()

    Extracts a part of a string and returns a new string

    split()

    Splits a string into an array of substrings

    substr()

    Extracts the characters from a string, beginning at a specified start position, and through the specified number of character

    substring()

    Extracts the characters from a string, between two specified indices

    toLocaleLowerCase()

    Converts a string to lowercase letters, according to the host's locale

      

    toLocaleUpperCase()

    Converts a string to uppercase letters, according to the host's locale

      

    toLowerCase()

    Converts a string to lowercase letters

    toString()

    Returns the value of a String object

    toUpperCase()

    Converts a string to uppercase letters

    trim()

    Removes whitespace from both ends of a string

    valueOf()

    Returns the primitive value of a String object

     

    Form对象

     

    属性名

    取值

    说明

    action

    action=”test.jsp”

    提交哪个jsp或servlet

    method

    post

    get

    提交方式。

    get缺点:

    (1)长度不可超过5k

     (2)以url形式出现在地址栏,不安全

    enctype

    multipart/form-data

    以二进制形式提交。用于上传文件

     

     

     

    Frame对象

    Frame调用页面内,和页面内调用frame外

    Frame调用内 

    document.getElementById("frameId").contentWindow.setQueryLayer("line, section, station");

     

     

    页面内调用外

    window.parent.receivefromGis(arrSendSubway);

     

    Frame去除边框

    "<iframe frame-border='0' ></iframe>"

     

     

    Object对象

    遍历对象的属性名

    遍历属性名

    var testObject={"Soul":"Shimada","Soul2":"Cozuka"};

    for(var temp in testObject){

           alert(temp);

    }

    //result: Soul, Soul2

     

     

     

    Input对象

    文本框自动补全

    //搜索工具, input-button-tips

    function searchTool(){

       var input=null;//关键字

       var button=null;//搜索

       var tips=null;//下拉选项

       var _this=this;

      

       //初始化

       this.init=function(inputDiv,butnDiv,tipsDiv){

          console.log("searchTool.init is called");

          if(inputDiv==null||inputDiv.tagName.toLowerCase()!="input"){

             console.log("invalid para,function searchToo.init()");

             return;

          }

          if(butnDiv==null||butnDiv.tagName.toLowerCase()!="input"){

             console.log("invalid para,function searchToo.init()");

             return;

          }

          if(butnDiv==null||tipsDiv.tagName.toLowerCase()!="div"){

             console.log("invalid para,function searchToo.init()");

             return;

          }

          input=inputDiv;

          button=butnDiv;

          tips=tipsDiv;

          console.log("searchTool widgets validated");

         

          //文本框获取焦点,显示tips

          $(input).on("focus",function(){

             console.log("input focus is triggered");

             _this.showTips(true);

          });  

          //文本框失去焦点

          $(input).on("blur",function(e){        

             //onblur,e always be input itsself

             //when tips.children.click caused inputBlur,

             //if not delay, showTips(false) precede children().click,

             //then unable to selected tip;

             console.log("input blur triggered,hideTips delayed 200ms");

             setTimeout(function(){

                _this.showTips(false);  

             },200);        

          });

          //关键字变更

          $(input).on("keyup",function(){

             console.log("input keyup is triggered");

             _this.updateTips($(this).val());

             _this.showTips(true);

          });

          $(button).on("click",function(){

             console.log("search click is triggered");

             var key=_this.getKey();

             console.log("关键字是:"+key);

             _this.showTips(false);

          });

          //点击tips以外的区域,tips关闭

       };//end 初始化 

       //获取输入的关键字

       this.getKey=function(){    

          return $.trim($(input).val());

       };

       //显隐备选项

       this.showTips=function(flag){

          console.log("showTips("+flag+") is called");

          if(flag){

             //显示

             if($(tips).hasClass("dNone")){

                if($(tips).children().length==0){

                    console.log("no children in tips,tips won't be showed");

                    return;

                }

                var left=$(input).css("left");

                var top=$(input).css("top")+$(input).css("height");

                console.log("tips location:"+left+","+top);

                $(tips).removeClass("dNone");

             }

             else{return;}

          }

          else{$(tips).addClass("dNone");}

       };

       //清空提示项,解除点击事件

       this.clearTips=function(){

          console.log("clearTips is called");

          var length=$(tips).children().length;

          console.log("tips.childeren.length is:"+length);

          $(tips).children().off("click");

          $(tips).empty();  

       };

       //更新tips

       this.updateTips=function(key){

          console.log("updateTips is called");

          this.clearTips();

          var stationTips=mapAppObj.stationIDNameObj.getSimilarStationNames(key);

          console.log("tips get,"+$.toJSON(stationTips));

          var tipsHtml="";

          for(var i=0;i<=stationTips.length-1;i++){

             tipsHtml+="<p class='similarItem'>"+stationTips[i]+"</p>";

          }

          $(tips).html(tipsHtml);

          $(".similarItem").on("click",function(){

             console.log("tipItem "+this.innerHTML+" is clicked");        

             $(input).val(this.innerHTML);

             _this.showTips(false);

          });

       };

    }

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    发送打印数据

    (1)点击打印

    this.exportGrid =function(){

           if (this.grid.store == null) {

               alert("尚未进行OD分析,无法导出表格");

               return;

           }

           var data = this.grid.store.data;

     

           if (data.length == 0) {

               alert("尚未进行OD分析,无法导出表格");

               return;

           }

           var tempStr = "<Xml dateTimeStr='" + $("#spanDateTimeTips")[0].innerText + "'>";

           for (var i = 0; i <= data.length - 1; i++) {

               tempStr += "<Route id='" + data[i].id + "' OriginName='" + data[i].OriginName + "' DestinationName='" + data[i].DestinationName + "' TransferName1='" + data[i].TransferName1 + "' TransferName2='" + data[i].TransferName2 + "' TransferName3='" + data[i].TransferName3 + "' TransferName4='" + data[i].TransferName4 + "' TransferName5='" + data[i].TransferName5 + "' Directions='" + data[i].Directions + "' Distance='" + data[i].Distance + "' TimeCost='" + data[i].TimeCost + "' StationCount='" + data[i].StationCount + "' CheckOutNum='" + data[i].CheckOutNum + "' ODPartition='" + data[i].ODPartition + "' ODTotal='" + data[i].ODTotal + "' Price='" + data[i].Price + "' ></Route>";

           }

           tempStr += "</Xml>";

     

           var xmlHttp = null;

           try { xmlHttp = new XMLHttpRequest(); }

           catch (e) {// Internet Explorer

               try {

                   xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

               }

               catch (e) {

                   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

               }

           }

     

           xmlHttp.onreadystatechange = function () {

               if (this.readyState == 4 && this.status == 200) {//callback

                   var xlsUrl = this.responseText;

                   document.getElementById("xlsLink").setAttribute("href", xlsUrl);

                   document.getElementById("xlsLink").click(); //下载xls文件            

                   unblockMapAppUI();

                   $("#imgExportExcel").removeClass("dNone");

               }

               else if (this.readyState == 4 && this.status == 500) {

                   alert("服务端处理excel异常");

                   console.log(this.responseText);

                   console.log(this.responseXML);

               }

           };

           var url = "../ServerScript/Handlers/getODHandler.ashx?type=exportExcel&time=" + new Date().toLocaleString();

           xmlHttp.open("POST", url, true);

           xmlHttp.send(tempStr);

           $("#imgExportExcel").addClass("dNone");

           $blockUI({message:'<h1><img src="../img/common.busy.gif"/>&nbsp;查询中...</h1>'});

       };

     

    key事件发生顺序

    结论:down-press-up

    $("#mLogin-inUsr").on("keydown",function(e){

          console.log("keydown");

       });

       $("#mLogin-inUsr").on("keyup",function(e){

          console.log("keyup");

       });

       //inUsr onChange  

       $("#mLogin-inUsr").on("keypress",function(e){    

          console.log("key press");  

       });  

    keydown-值未变

    结论:keydown发生时,值未变

       $("#mLogin-inUsr").on("keydown",function(e){     

          console.log("keydown");

          console.log($.trim($("#mLogin-inUsr").val()));   

       });

    keypress-值未变

    $("#mLogin-inUsr").on("keypress",function(e){    

          console.log("keypress");

          console.log($.trim($("#mLogin-inUsr").val()));   

       });

     

    keyup-值已变

       $("#mLogin-inUsr").on("keyup",function(e){    

    console.log("keyup");

          console.log($.trim($("#mLogin-inUsr").val()));   

       });

     

     

     

     

     

     

    Array对象

    数组,排序, 升序和降序,删除

    升序:

    function sortFunction(a,b)

    {

    return a - b

    }

     

    降序:

    function sortFunction (a,b)

    {

    return b- a

    }

     

    调用方式:

    ar.sort(sortFunction);

    备注:执行后,数组顺序将改变

    中文按拼音顺序排序

    //按站名排序

       var sortGraphicsByName=function(b,a){

          return b.attributes.NAME.localeCompare(a.attributes.NAME);

       };

     

     

    数组, pop和splice

     Arr.pop() 删除并返回最后一个元素

     Splice(i,1)删除第i个元素

     

    删除1:

    keys.splice(tempIndex, 1);//删除不限

    备注:方法1得到的是剩余元素构成的数组。

     

     

    删除2:

    keys=keys.splice(tempIndex, 1);//删除不限

     

    备注:方法2得到的是被删除元素形成的数组。

    从数组中删除元素,loop必须用递减

     

     

     

    数组拷贝

    法1:

    var arrB=arrA;

     

    法2:

    for(var i=0;i<=arrA.length-1;i++){

       arrB.push(arrA[i]);

    }

    JS 数组合并排序

    A:[1,3,5,7,9]

    B:[1,3,6,8,10]

    输出:

    [1,3,5,6,7,8,9,10]

     


    LocalStorage对象

    只能存字符串

    localStorage.setItem(‘test’,[1,2,3]);

     

    localStorage.getItem(‘test’);

     

    移除

    localStorage.removeItem(‘test’);

     

     

     

    Table对象

    内存泄露

     

    方案1:使用innerHTML清空table

     

     

    添加900行后

     

     

    Div.innerHTML=””之后

     

     

    泄露大小:6M

    泄露比率:6M/12M=50%

     

    增删10次后内存:56M

    每次增加比率:0.1/60. 

     

     

    方案2:使用deleteRow清空table

       else if(e.target.id=="btnRemoveRows"){

             var tempTb=document.getElementById("tbMemoCheck");

             for(var i=tempTb.rows.length-1;i>=0;i--){

                tempTb.deleteRow(i); 

             }

             return false;

          }

     

     

    添加900行后:

     

    DeleteRow之后:

     

     

    泄露大小:6M

    泄露比率:6M/12M=50%

     

    增删10次后

     

    泄露增值:7M-6M=1M;

    每次增加比率:0.1/60. 

     

    结论:

      使用innerHTML=””;

           和deleteRow效率相同;

     

     

     

    附录:代码

     

    <style type="text/css">

    #dvTableArea{

      width:800px

      height:600px;

      overflow:scroll;

    }

    #dvTableArea table{

       border:1px solid #000;  

    }

    td{

      border:1px solid #000

    }

    </style>

    <script type="text/javascript">

    window.οnlοad=function(){

       makeAndBind();

    };

    function clearRows(){

       document.getElementById("dvTableArea").innerHTML="";

    }

    function appendRows(){

       clearRows();

        var innerString='<table id="tbMemoCheck" cellSpacing="0px">';

          for(var i=0;i<=900;i++){

             innerString+='<tr>';

             for(var j=0;j<=10;j++){

                var cellText="cell("+i+","+j+")";

                innerString+='<td>'+ cellText+'</td>';

             }

             innerString+='</tr>';

          }

          innerString+='</table>';  

          document.getElementById("dvTableArea").innerHTML=innerString;

    }

    //javascript 的 make and bind

    function makeAndBind(){   

       document.body.οnclick=function(e){

          if(e.target.tagName.toLowerCase()=="td"){

             console.log(e.target.innerHTML+" is clicked");

             return false;

          }

          else if(e.target.id=="btnAddRows"){

             appendRows();

             return false;

          }

          else if(e.target.id=="btnRemoveRows"){

             clearRows();            

             return false;

          }

          return false;

       }

    }

    </script>

    </head>

    <body class="tundra">

    <div><input type="button" id="btnAddRows" value="添加行"><input type="button" id="btnRemoveRows" value="删除行"></div>

    <div id="dvTableArea"></div>

    </body>

    </html>

     

     

     

     

    Date对象

    时刻差

    结论:用于判断哪个方法执行时间长。 提高程序效率

     

    var start=new Date();

       submit(url, postData,function(rData){  

             var end=new Date();

             console.log("请求rData时间:"+(end.getTime()-start.getTime())+"毫秒");

    DOM事件

    绑定

    备注:不依赖javascript框架,拓展性极强.

          请优先于jquery和dojo的绑定方式使用

    function bindEvents(){

       document.getElementById("inpTest").οnfοcus=function(){

          console.log("inpTest is focused");

       };

       document.getElementById("inpTest").οnblur=function(){

          console.log("inpTest is blured");

       };

       document.getElementById("inpTest").οnclick=function(){

          console.log("inpTest is clicked");

       };

       /*不支持

       document.getElementById("inpTest").onclick(function(){

          console.log("inpTest is clicked");

       });

       */

       document.getElementById("btnUnBind").οnclick=function(){     

       }

    }

     

     

    取消绑定

    键盘事件  onkeypress

     

    <input type="text" id="inpNameKey" value="关?键¨¹字Á?" οnkeypress="checkKey(event)"

     

     

    Onkeydowm,onkeyup 连选选择

       function allowContinSel(e) {

            if (e.keyCode == 16) {

                alert("允¨许¨连续选择");

            }

        }

        function forbidenContinSel(e) {

            if (e.keyCode == 16) {

                alert("连续选择终止");

            }

        }

    </script>

    </head>

    <body class="claro" οnkeydοwn="allowContinSel(event)" οnkeyup="forbidenContinSel(event)">

     

     

    On 绑定多次, Off关闭

     

    <script type="text/javascript">

    function bindClick(){

       console.log("bindClick is called");

       //on("click"), bind one, execute one. bind many times, execute manyTimes

       $("#testDv").on("click",function(){

          console.log("testDv is clicked");

       });            

    }

    //off, many times before, no on("click") after using off("click")

    function unbind(){

       $("#testDv").off("click");

    }

    $(document).ready(function(){

       bindClick();

    });

    </script>

     

     

    Console:

     

     

    所有事件处理结束后 return false

    Return false.  防止寻找其它handler

    Blur事件 对象

    序号

    对象

    是否能触发blue

    1

    input type=”text”

    true

     

    input type=”button”

     

     

     

     

    2

    span

    false

     

    label

    false

     

     

     

    冒泡和捕获

    触发顺序

    1. 当父元素和子元素都绑定了click,总是先触发最内层元素的click

     

    2. 当只绑定了父元素click,通过e.target可以获取子元素

     

     

     

     

     

    tr.click绑定 ,td.click绑定, 点击td

     

    结论:

    (1)td click后,会自动触发tr click

       (2)在td.click 末尾添加 return false,可阻止tr.click

       触发顺序是 最内层元素 依次向外

     

    代码

    <script type="text/javascript">

      $(document).ready(function(){

         bindUIEvents();

      });

      //情况1: td tr都绑定了click事件,点击td。

      //发生顺序:td.click,->tr.click。

      //屏蔽方式:td.click 处理中添加 return false;

      function bindUIEvents(){

         $(".row").on("click",function(e){

            console.log("row is clicked");

         });

         $("td").on("click",function(e){      

            console.log("td "+$(e.target)[0].innerHTML+" is clicked");

            return false;

         });

      }

    </script>

    <style>

     td{border:1px solid rgb(0,0,0);}

     table{border-collapse:collapse;}

    </style>

    </head>

    <body>

    <table><tr class="row"><td class="col1">cell1</td><td class="col2">cell2</td><td class="col3">cell3</td></tr></table>

    </body>

     

     

     

    tr.click绑定,td不绑定,点击td

     

    结论:

    (1)tr.click被触发

      (2)通过e.target可以获取到td

     

    价值:

    对大容器绑定一次, 容器里面的元素不绑定,通过r.target可在一个handler中处理所有事件。

     

     

     

    //情况2:tr绑定click,td不绑定click。

       //点击tr中的td, tr.click触发,通过 e.target能获取到是哪个td被点击.

      function bindUIEvents(){

         $(".row").on("click",function(e){

            console.log("row is clicked");

            console.log("cell is:"+$(e.target)[0].innerHTML);

         });

    }

     

    <table><tr class="row"><td class="col1">cell1</td><td class="col2">cell2</td><td class="col3">cell3</td></tr></table>

     

     

     

     

    阻止事件向父元素传播

    子元素click中:

    return false;

     

     

     

    DOM元素操作

    删除

    window.parent.document.body.removeChild(window.parent.document.getElementById("dvFrameOD"));

    创建并绑定(入门)

    说明:两种情况能找到创建的dom元素

           -1. Var domA=document.createElement(“div”);

             domA.οnclick=function(){}; //

    -2.var domB=document.createElement(“div”);

        domB.innerHTML=”<input id=’input1’>”;

       document.appendChild(domB);

    //注意,append之后才能直接getElementById

       document.getElementById(“input1”).οnclick=function(){

    };

     

     

    //javascript 的 make and bind

    function makeAndBind(){ 

        var operPane=document.createElement("div");

        var innerString="";

        for(var i=0;i<=2;i++){    

           var tempId='input'+i.toString();

           var value='input'+i.toString();

           innerString+='<input type="text" value='+value+' id='+tempId+'>';

        }

        operPane.innerHTML=innerString;

        document.getElementById("testDv").appendChild(operPane);

        //备注:只有在append之后,getElementById才能获取到

        for(var i=0;i<=2;i++){

           if(document.getElementById("input"+i.toString())==null){

              console.log("input"+i.toString()+" is not found");

              continue;

           }

           document.getElementById("input"+i.toString()).οnclick=function(e){

             console.log(e.target.id+" is clicked");

           };

        }

    }

     

     

    创建并绑定 (一个容器,下辖多个元素)

    说明:

      创建div,div内用innerHTML创建3个input,

      在div.onclick判断哪个子元素触发事件.

     

    优点:只append一次.

    只有一个onclick事件.

    在appendChild之前也可绑定事件

    适用于多层结构的情况

     

    //javascript 的 make and bind

    function makeAndBind(){ 

       //div容器

        var operPane=document.createElement("div");

        var innerString="";

        //div容器 子元素html

        for(var i=0;i<=2;i++){    

           var tempId='input'+i.toString();

           var value='input'+i.toString();

           innerString+='<input type="text" value='+value+' id='+tempId+'>';

        }

        operPane.innerHTML=innerString;

        

        //在div的click中处理所有子元素的事件

        operPane.οnclick=function(e){

           var id=e.target.id;

          if(id!=""){//子元素被点击

             console.log(id+" is clicked");

             return false;

          }      

          else{//div被点击

             console.log("div 被点击");

             return false;

          }   

        }

        //appendDiv

        document.getElementById("testDv").appendChild(operPane); 

    }

    创建并绑定(一个容器,下辖多个元素,元素下又辖元素)

    三部曲:

    -1  div.container=document.createElement(“div”);

    -2  div.innerHTML=htmlString;

    -3  div.οnclick=function(e){

      var targetId=e.target.id;

      if(targetId==””){

    }

    Else if(){

    }

    }

    备注:使用createElement创建的dom元素,在appendChild之前也可onclick

    //javascript 的 make and bind

    function makeAndBind(){ 

       //div容器

        var operPane=document.createElement("div");

        var innerString=""; 

        //div容器 子元素html

        for(var i=0;i<=2;i++){    

           var tempId='Level1-'+i.toString();

           var value='Level1-'+i.toString();

           if(i!=2){

              innerString+='<div type="text" value='+value+' id='+tempId+'>'+value+'</div>';     

           }

           else{

              innerString+='<div type="text" value='+value+' id='+tempId+'>';

              for(var j=0;j<=2;j++){

                 var tempId='Level2'+j.toString();

                 var value='Level2'+j.toString();

                 innerString+='<input type="text" value='+value+' id='+tempId+'>';

              }

              innerString+='</div>';

           }

        }

        operPane.innerHTML=innerString;

        

        //在div的click中处理所有子元素的事件

        operPane.οnclick=function(e){

           var id=e.target.id;

          if(id!=""){//子元素被点击

             console.log(id+" is clicked");

             return false;

          }      

          else{//div被点击

             console.log("大容器 被点击");

             return false;

          }   

        }

        //appendDiv

        document.getElementById("testDv").appendChild(operPane); 

    }

     

    <body class="tundra">

      <div id="testDv"></div>

    </body>

    清空元素下所有子节点

    document.getElementById(graphicAddedTime).innerHTML="";

     

     

     

     

     

     

    XMLHttpRequest和Ajax

    AJAX军规

    在url后面添加?time=一个不会重复的时间, 否则将受缓存影响

        var url = "http://localhost/ODWeb/getODHandler.ashx?type=&time=" + new Date().toLocaleString();

            xmlHttp.open("POST", url, true);

            xmlHttp.send(postData);

     

     

     

     

     

     

     

     

     

     

     

     

     

    AJAX GET

    function sendReq() {

            var xmlHttp = GetXmlHttpObject();

            xmlHttp.onreadystatechange = function () {

                if (this.readyState == 4) {

                    alert(this.responseText); //call back snippets, use responseText for data

                  

                }

            };

            var url="photos.json";

            xmlHttp.open("GET", url, true);

            xmlHttp.send(null);

        }

     

        function GetXmlHttpObject() {

            var xmlHttp = null;

            try {

                // Firefox, Opera 8.0+, Safari

                xmlHttp = new XMLHttpRequest();

            }

            catch (e) {

                // Internet Explorer

                try {

                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

                }

                catch (e) {

                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

                }

            }

            return xmlHttp;

        }

    AJAX POST

     

    function sendReq() {

            var xmlHttp = GetXmlHttpObject();

            xmlHttp.onreadystatechange = function () {

                if (this.readyState == 4) {

                    alert(this.responseText); //call back snippets, use responseText for data

                }

            };

            var url = "../getODHandler.ashx";

            xmlHttp.open("POST", url, true);

            xmlHttp.send(postData);

        }

     

        function GetXmlHttpObject() {

            var xmlHttp = null;

            try {

                // Firefox, Opera 8.0+, Safari

                xmlHttp = new XMLHttpRequest();

            }

            catch (e) {

                // Internet Explorer

                try {

                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

                }

                catch (e) {

                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

                }

            }

            return xmlHttp;

        }

     

     

    AJAX军规,异步请求 线数据,站数据,时间数据

    3种请求无前后关系,

    ajax(“linedata”,function(){ bindlineEvent();});

    ajax(“stationdata”,function(){ bindstationEvent();});

    ajax(“stationdata”,function(){ bindyearEvent();});

    AJAX军规-加时间,防止读缓存

    在url后面添加?time=一个不会重复的时间, 否则将受缓存影响

        var url = "http://localhost/ODWeb/getODHandler.ashx?type=&time=" + new Date().toLocaleString();

            xmlHttp.open("POST", url, true);

            xmlHttp.send(postData);


    动态Html字符串

    动态background-position样式

    $(document).ready(function(){

           var htmlStr="";

           for(var i=0;i<=9;i++){             

              htmlStr+='<div style="background:url(../img/markers.png) 0px '+(-(i*25)).toString()+'px"></div>';       

           }

           $("#testDiv").html(htmlStr);

    });

     

     

    备注:注意position数值,注意url引号。

     

    效果


    类和对象

     

    Javascript 私有方法/公有方法

    function testClass(){

       this.publicHello=function(){

          return "publicHello";

       };

      

       var privateHello=function(){//私有方法,obj.privateHello无法调用

          return "privateHello";

       };

       this.callPrivate=function(){     

          var value=privateHello();

          return value;

       };

       this.callPrivate2=function(){

          var value=this.privateHello();//调用私有方法不能用this

          return value;

       };

    }

    /*调用举例

     * var testObj=new testClass();

     * testObj.publicHello(); //"publicHello";

     * testObj.privateHell():// undefined;

     * testObj.callPrivate(); //"privateHello";

     * testObj.callPrivate2(); //undefined;

     */

     

    Javascript  访问公有成员(inside private M)

    <html>

    <head>

       <title>private method 调用成员,public method 调用成员</title>

       <script type="text/javascript">

          function CTest(){

             this.member="member of  CTest";

             var _this=this;

             var privateVisit=function(){

                console.log("privateVisit, this.member is:"+this.member);

                console.log("privateVisit,_this.member is:"+_this.member);

             }

             this.publicVisit=function(){

                console.log("publicVisit,this.member is:"+this.member);

             }

            

             this.callPrivateVisit=function(){

                privateVisit();

                console.log("callPrivateVisit triggered privateVisit()");

             }

          }

       </script>

    </head>

    <body>

    <script type="text/javascript">

       var testObj=new CTest();

       testObj.callPrivateVisit();

       testObj.publicVisit();

    </script>

    </body>

    </html>

     

    控制台:

    privateVisit, this.member is:undefined

     privateVisit,_this.member is:member of  CTest

     callPrivateVisit triggered privateVisit()

     publicVisit,this.member is:member of  CTest

     

    Javascript 私/公  访调顺序

     

     

    <html>

    <head><title>私/公  声调顺序</title></head>

    <script type="text/javascript">

     function CTest1(){

        try{

          privateLog();

          var privateLog=function(){

              console.log("privateLog has been called");

          };

        }

        catch(e){

           console.log(e.descripiton);

        }

     }

     function CTest2(){

        try{

          this.publicLog();

          this.publicLog=function(){

              console.log("publicLog has been called");

          };

        }

        catch(e){

           console.log(e.description);

        }

     }

    </script>

    <body>

    <script type="text/javascript">

      var test1=new CTest1();

      var test2=new CTest2();

    </script>

    </body>

    </html>

     

    控制台:

    undefined

     对象不支持“publicLog”属性或方法

     

    结论:必须先声明,后调用

     

    Javascript 调用私有方法 

    This.M(), _this.M() failed.

    M() works;

     

    <html>

    <head><title>don't use this.method to call private method</title></head>

    <script type="text/javascript">

     function CTest1(){

        var _this=this;  

           var privateA=function(){

             console.log("privateA has been called");

          }

          

          var privateB=function(){

             console.log("call privateA()");

              privateA();      

              console.log("\ncall _this.privateA() in privateB");

              try{

                _this.privateA();    

              }

              catch(e){

                 console.log(e.description);//_this.privateMethod()不能调用私有方法

              }

          };

         

          privateB();//第一次执行privateB()

         

          try//第二次执行privateB();

          {

             console.log("\ncall this.privateB()");

             this.privateB();

          }

          catch(e){

             console.log(e.description);

          }

    }

    </script>

    <body>

    <script type="text/javascript">

      var test1=new CTest1();

    </script>

    </body>

    </html>

     

    控制台:

    call privateA()

     privateA has been called

     
    call _this.privateA() in privateB

     对象不支持“privateA”属性或方法

     
    call this.privateB()

     对象不支持“privateB”属性或方法

    Javascript 类 (时刻,时间类)

     

    //时º¡À刻¨¬

     

        this.hour = parseInt(h);

        this.minute = parseInt(m);

        this.totalMinutes = this.hour * 60 + this.minute; //分¤?钟¨®总Á¨¹数ºy,ê?用®?于®¨²排?序¨°

        return this;

    }

    Moment.prototype.isSame = function (moment) {

    if (this.hour == moment.hour && this.minute == moment.minute) { return true; }

    else { return false; }

    }

    Moment.prototype.isBefore = function (moment) {

    if (this.hour < moment.hour) { return true; }

    else if (this.hour == moment.hour) {

    if (this.minute < moment.minute) { return true; }

    else if (this.minute == moment.minute) { return false; }

    else { return false; }

    }

    else {

    return false;

    }

    }

    Moment.prototype.isAfter = function (moment) {

    if (this.hour > moment.hour) { return true; }//7:00. 7:01

    else if (this.hour == moment.hour) {

    if (this.minute > moment.minute) { return true; }

    else if (this.minute == moment.minute) { return false; }

    else { return false; }

    }

    else {

    return false;

    }

    }

     

    //时段

    function Period() {

    if (arguments.length != 4 && arguments.length != 2) {return null;}

    if (arguments.length == 4) {

    var startH = arguments[0];

    var startM = arguments[1];

    var endH = arguments[2];

    var endM = arguments[3];

    if (startH > endH) { return null; }

    else if (startH == endH) {

    if (startM > endM) { return null; }

    }

    this.startMoment = new Moment(startH, startM);

    this.endMoment = new Moment(endH, endM);

    this.startMinutes = this.startMoment.totalMinutes;

    this.endMinutes = this.endMoment.totalMinutes;

    this.length = this.endMoment.totalMinutes - this.startMoment.totalMinutes;

    return this;

    }

    else {

    this.startMoment = arguments[0];

    this.endMoment = arguments[1];

    this.startMinutes = this.startMoment.totalMinutes;

    this.endMinutes = this.endMoment.totalMinutes;

    this.length = this.endMoment.totalMinutes - this.startMoment.totalMinutes;

    return this;

    }

    }

     

    /*

    参数:

    返回:

    */

    Period.prototype.isSame = function (objPeriod) {

        if (this.startMoment.isSame(objPeriod.startMoment) && this.endMoment.isSame(objPeriod.endMoment)) { return true; }

        else { return false; }

    }

     

    Period.prototype.containMoment = function (moment) {

        if ((this.startMoment.isSame(moment) || this.startMoment.isBefore(moment)) && (this.endMoment.isSame(moment) || this.endMoment.isAfter(moment))) {

            return true;

        }

        else {

            return false;

        }

    }

    /*获取已选时段*/

    function getPeriodArrayString(arrPeriods) {

        var result = "已°?选?时º¡À段?:";

        arrPeriods.sort(sortPeriodsByStartMoment);

        for (var i = 0; i <= arrPeriods.length - 1; i++) {

            result += arrPeriods[i].startMoment.hour + ":" + arrPeriods[i].startMoment.minute + "-" + arrPeriods[i].endMoment.hour + ":" + arrPeriods[i].endMoment.minute + ",";

        }

        result = result.substr(0, result.length - 1);

        return result;

    }

     

    JS时段合并

    /*合并两个period

    */

    function combineTowPeriod(last, prev) {

        if (last.startMinutes > prev.endMinutes) {//左 离

            return null;

            console.log("0");

        }

        else if (last.startMinutes == prev.endMinutes) { //左共时刻

        return (new Period(prev.startMoment, last.endMoment));

            console.log("1");

        }

        //左部分相交

        else if (last.startMinutes < prev.endMinutes && last.startMinutes > prev.startMinutes && last.endMinutes > prev.endMinutes) {

            return (new Period(prev.startMoment, last.endMoment));

            console.log("2");

        }

        //真包含

        else if (last.startMinutes <= prev.startMinutes && last.endMinutes >= prev.endMinutes) {

            return (new Period(last.startMoment, last.endMoment));

            console.log("3");

        }

        //右部分相交

        else if (last.endMinutes > prev.startMinutes && last.endMinutes < prev.endMinutes) {

            return (new Period(last.startMoment, prev.endMoment));

            console.log("4");

        }

        //右共时刻

        else if (last.endMinutes == prev.startMinutes) {

                return (new Period(last.startMoment, prev.endMoment));

            console.log("5");

        }

        //右 离

        else if (last.endMinutes < prev.startMinutes) {

            console.log("6");

            return null;

        }

        else {

            alert("预期外组合出现");

            return null;

        }

    }

     

    /*描述:时段区间合并算法

    */

    function simplifyPeriodArray(arrPeriods) {

        if (arrPeriods.length <= 1) {return arrPeriods;}

        var haschanged = false;

        do {

            for (var j = arrPeriods.length - 1; j >= 0; j--) {

                arrPeriods.sort(sortPeriodsByLength); //重新排序

                haschanged = false;

                var longestP = arrPeriods[j];//从尾取最长

                for (var i = j-1; i >= 0; i--) {//合并j之前的i

                    var newP = combineTowPeriod(longestP, arrPeriods[i]);

                    if (newP == null) { continue; }

                    else {

                        haschanged = true;

                        arrPeriods.splice(j, 1, newP); //替换最长

                        longestP = newP;

                        arrPeriods.splice(i, 1);//删除被合并

                    }

                }//end for

            } //end for

        } while (haschanged);

    }

     

    JS 拷贝一个javascript对象/数组

    背景:javascript对象都是引用类型.拷贝有两种方式:

      方式1:重新构造javascript对象B,将A的属性逐个赋值到B上。

      方式2:将A转成字符串,

    创建对象B=JSON.parse(字符串)

    下面介绍这种方式:

     

    var jsonObj={x:101,y:102};

    var tempObj=jsonObj;

    tempObj.x=100;

    console.log(jsonObj.x==tempObj.x);

     

    var jsonStr=JSON.stringify(jsonObj);

    var newObj=JSON.parse(jsonStr);

    newObj.x=103;

    console.log(jsonObj.x==newObj.x);

     

     

     

     

     


     

    JS静态类  (JSON对象属性作为方法)

    var staticClass={

          sayHello:function(){

             console.log("hello");

          } 

    };

     

    $(document).ready(function(){

       staticClass.sayHello();

    });

    静态类方法A调用方法B

    var staticClass={

          sayHello:function(){

             staticClass.getConstantPI();

          },

          getConstantPI:function(){

             console.log(Math.PI);

          }

    };

     

     

     

     

    拷贝/镜像应用

    Copy步骤

     1.找主页html,下载.

     2. 从主页link和script建立对应的目录结构. 下载js,css文件

     3.捕捉XMLHttpRequest Header头和url,data. 将reponseData存成json或者xml以供显示

     

    Copy成果:

      YYDA

     

     

     

    应用举例

    Script5  拒绝访问 (门户如何集成n个网站)

    描述:

      <html>

    ..<title>门户首页</title>..

        …<iframe src=”跨域页.html”></iframe>..

    </html>

     

     

    <html>

    ..<title>跨域页.html</title>..

           …<script src=”jquery.js”></>...

           <script >

          $(document).ready(function(){

    });

    </script>

    </html>

     

    报错;

      Script 5:拒绝访问

      $ 未定义

     

     

     

    解决方式

     

      <html>

    ..<title>门户首页</title>..

        …<iframe src=”无jq跨域页.html”></iframe>..

    </html>

     

     

    <html>

    ..<title>无jq跨域页.html </title>..

           <iframe src=”jq页.html”></iframe>

    </html>

     

    <html>

    <title>jq页.html<title>

    <script src=”jquery.js”></script>

    <script>

           $(document).ready(function(){

                 

    });

    </script>

    </html>

     

     


    4800个点,智能获取首坐标

    代码清单:

    (1)autoObj

    (2)startNextLoop

    (3)autoBind

    ---

    //自动绑定, 用控制台,未UI

       autoObj:{

          //localSearchOption

          searchOption:{

             //回调函数

             onSearchComplete:function(results){

                try{              

                    var resultStr="第"+shopMisUtil.autoObj.responseNum+"个响应,";

                    shopMisUtil.autoObj.responseNum++;

                    //获取发起shop

                    var sourceKey=results.keyword;

                    var sourceShop=function(){

                       for(var j=0;j<=shopMisUtil.shops.length-1;j++){

                          if(shopMisUtil.shops[j].Address==sourceKey){

                             return shopMisUtil.shops[j];

                          }                    

                       }                                

                       return null;

                    }();

                   

                    //未找到地址

                    if (results.getCurrentNumPois()==0){                

                       sourceShop.Longitude=null;

                       sourceShop.Latitude=null;                  

                       resultStr+="\""+sourceKey+"\"未找到地址";

                       console.log(resultStr);             

                   }

                    else{

                    //找到地址

                       sourceShop.Longitude=results.getPoi(0).point.lng;

                       sourceShop.Latitude=results.getPoi(0).point.lat;

                       resultStr+="\""+sourceKey+"\"坐标是:("+sourceShop.Longitude+","+sourceShop.Latitude+")";

                       console.log(resultStr);

                    }

                    //如果响应数目整数倍

                    var modVal=shopMisUtil.autoObj.responseNum%shopMisUtil.autoObj.reqPerLoop;                        

                    if(modVal==0){                

                       startNextLoop(shopMisUtil.autoObj.responseNum);                                                      

                    }

                    return;

                }

                catch(e){

                    alert(e.description);

                    return;

                }

             }

          },

          responseNum:0,//已经回应多少条     

          reqPerLoop:1000,//每轮请求多少个 100个占用350M内存,1000 450M

          startNum:0,//从第几个开始绑定

          maxNum:0,//找到第几个商店就不找了 0- lengh-1

       },

     

    //自动绑定坐标

    function autoBind(num){

       //已绑定个数 0

       shopMisUtil.autoObj.responseNum=0;

       if(num==null){startNextLoop(0);}

       else{startNextLoop(num);}

    }

     

    function startNextLoop(fromNum){

       var toNum;

       if(shopMisUtil.autoObj.maxNum!=0){

          toNum=(fromNum+shopMisUtil.autoObj.reqPerLoop-1)<(shopMisUtil.autoObj.maxNum)?(fromNum+shopMisUtil.autoObj.reqPerLoop-1):(shopMisUtil.autoObj.maxNum);

       }

       else{

          toNum=(fromNum+shopMisUtil.autoObj.reqPerLoop-1)<(shopMisUtil.shops.length-1)?(fromNum+shopMisUtil.autoObj.reqPerLoop-1):(shopMisUtil.shops.length-1);  

       }

      

       console.log('startNextLoop triggered, from '+fromNum+' to '+toNum);

       for(var i=fromNum;i<=toNum;i++){

          var oneShop=shopMisUtil.shops[i];

          var oneKey=oneShop.Address;      

          var oneSearch=new BMap.LocalSearch(shopMisUtil.mp,shopMisUtil.autoObj.searchOption);

          console.log("第"+i+"个地址\""+oneKey+"\"搜索开始");

          oneSearch.search(oneKey);

       }

    }

     

     

     

     

     

     

     

    4800个点,智能更新Oracle中坐标

     

    原理:一次发送10个点。Ajax回调后,再发10个

     

    为何只发10个:

     发20个时,Svt中解析时出错,未查明原因。

     

     

    代码:

       updateObj:{

          upNumPerLoop:10,//每次向tomcat更新多少个商店的位置,1次更新                     //10, 480条/分钟

          updatedNum:0//已更新位置    

       },

     

    //更新所有商户位置

    function updateAllShops(){    

       var url="../ShopCudes"; 

       //逐个发送

       shopMisUtil.updateObj.updatedNum=0;

       var nextLoop=function(){

          if(shopMisUtil.updateObj.updatedNum<shopMisUtil.shops.length){

                var tempAr=[];

                var tempNum=0;

                var cur=tempNum+shopMisUtil.updateObj.updatedNum;

                while(tempNum<shopMisUtil.updateObj.upNumPerLoop&&cur<shopMisUtil.shops.length){

                    var oneShop=shopMisUtil.shops[cur];

                    tempAr.push(oneShop);

                    tempNum++;

                }                 

                shopMisUtil.submit(url,{cmd:1,data:tempAr,condition:null},function(rData){

                    var result=eval(rData)[0];

                    if(result.Done==true){

                       console.log("全商户,"+result.Info);

                    }

                    else{

                       console.log("全商户更新失败");

                    }    

                   shopMisUtil.updateObj.updatedNum+=shopMisUtil.updateObj.upNumPerLoop;

                    nextLoop();

                });

          }

          else{

             console.log("全商户位置绑定完成");

          }

       };

       nextLoop();

    }

     

     

    界面举例

    组类UI处理方式

    说明:

     起点时段:shour,ehou,sminute,eminute,addedTimeO

      终点时段:shour,ehou,sminute,eminute,addedTimeD

     

    要进行的操作相同,仅仅DOM对象不同。

    处理方式:设置5个对象,从界面条件,将5个对象指向。

     

     

     

    var targetAddedTime = {};

                    var inpStartHour = {};

                    var inpStartMinute = {};

                    var inpEndHour = {};

                    var inpEndMinute = {};

                    var targetGraphicLayer = {};

                    if (this.id == "customOriginTime") {

                        targetAddedTime = $("#addedTimeOrigin")[0];

                        inpStartHour = $("#inpOHourStart")[0];

                        inpEndHour = $("#inpOHourEnd")[0];

                        inpStartMinute = $("#inpOMinuteStart")[0];

                        inpEndMinute = $("#inpOMinuteEnd")[0];

                        targetGraphicLayer = graLayerSelectO;

                    }

                    else {

                        targetAddedTime = $("#addedTimeDestination")[0];

                        inpStartHour = $("#inpDHourStart")[0];

                        inpEndHour = $("#inpDHourEnd")[0];

                        inpStartMinute = $("#inpDMinuteStart")[0];

                        inpEndMinute = $("#inpDMinuteEnd")[0];

                        targetGraphicLayer = graLayerSelectD;

                    }

    后续语句将相同

     

    报表样式设计

    --1表头

    --2左右有页边距

    --3表头字体比表中数字明显

    --4下页面有阴影效果

     

     

     

     

     

     

     

     

     

     

    AMD 规范

    概要

    AMD= Asychronous Module Definition

    异步模块规范。 作用是异步加载js类。比传统的(Legacy Module Definition)效率高。

     

    实现了AMD规范的js库有RequireJS 、curl 、Dojo 、bdLoadJSLocalnet 、Nodules 等。

    AMD require

     用于加载js模块

    举例:

    require([module], callback); 

    第一个参数[module],是一个数组,里面的成员就是要加载的模块;第二个参数callback,则是加载成功之后的回调函数。

    举例:

    require(['math'], function (math) { math.add(2, 3);}); 

     

    math.add()与math模块加载不是同步的,浏览器不会发生假死。所以很显然,AMD比较适合浏览器环境。

    AMD define

     


    ASCII 128个

    不可见:33个

     

    可见:95个

    字母 52个

    数字行 26个

    键盘右侧 16个

    空格   1个

     

     

     

    加密和解密

    密码字符集

     

    95个可显示字符中,除去空格。

    94

     

    字母:52

    数字行:26

    右侧符号:16

     

    结论:

     不包含汉字

     

    escape和unesace

    escape原理:

    (1)95个可显ASCII字符不变。其它字符变。

     

     

    举例:

    var psw="abcdefghijhlmnopqrstuvwxyz1234567890+-*/%!@#^&{}()<>.,;'你好";

       var esed=escape(psw);

       var unesed=unescape(esed);

       console.log("escaped:"+esed);

       console.log("unesed:"+unesed);

     

    缺点:

      (1)不加密字符数字

    结论:

      不用。

     

     

    字符 和Unicode 转换

    Unicode即万国码,全球所有字符。共65536个。

    使用0-65535这些数值,建立字符-数值一一映射。

     

    结论:比escape强,但需要进一步编码

          charCodeAt-将字符转成 unicode数值

          fromCharCode-将unicode数值转成 字符

     

    //var str='1234qwER你好';

     StrUTF8数组

        function toUtf(str){

           var result=[];

           for(var i=0;i<=str.length-1;i++){       

              result.push(str.charCodeAt(i));         

           }

           console.log(str +" utf8:"+result);

           return result;

    }

     

     

     

     

     

    UTF8数组转Str

        function toStr(arr){

           var result="";

           for(var i=0;i<=arr.length-1;i++){

              result+=String.fromCharCode(arr[i]);

           }

           console.log(result);

           return result;

        }

     

     

    1234qwER你好 utf8:49,50,51,52,113,119,69,82,20320,22909

    [49, 50, 51, 52, 113, 119, 69, 82, 20320, 22909]

     

    toStr(ar)

    1234qwER你好

     

     

    举例:

    ende.encrypt("1234qweTFD你好");

    [49, 50, 51, 52, 113, 119, 101, 84, 70, 68, 20320, 22909]

    BCDEveWU佱妎

     

    ende.decrypt("BCDEveWU佱妎")

    1234qweTFD你好

     

     

    sha256散列 密码

     

    评定:

    比plain Text安全。

    其它网站账户安全。

     

    引用:sha256.js

    加密:

       var str="1234qwER你好世界";

    sha256_digest(str)

    "40dcee1b329f479172692e6213bbcf43d7c2229d49be5565ae811db3b84fb4ec"

    结果:

    64位的hash序列。

     

    特点:不可逆

         数据库存放hash序列,不存放密码

     

    展开全文
  • 课程链接:http://underactuated.csail.mit.edu/Spring2019/ ...欠驱动机器人学Underactuated Robotics Algorithms for Walking, Running, Swimming, Flying, and Manip...
  • ​ —Dave Kekich Part 01 Self-discipline means living your life the hard way: resisting temptations and instant gratification1 , in order to receive bigger and better rewards in the future....
  • 混沌工程工具-阿里ChaoBlade的实现说明 1.概述 ...Chaos Engineering is the discipline of experimenting on a system in order to build confidence in the system’s capability to withstand turbul
  • Also, throughout the project, I would suggest that you question the value of the tests allotted to you, since no test process provides complete coverage. To improve the breadth and depth of your ...
  • A classifier is a system that inputs (typically) a vector of discrete and/or continuous feature values and outputs a single discrete value, the class. For example, a spam filter classifies email ...
  • 测试人员的情人节

    2019-07-28 19:26:46
    testers just want to test, and they enjoy their unique, skilled discipline. 作为一个有价值的队友,重要的是要记住测试人员应该被开发者平等对待。 具有相同经验的角色的测试人员和程序员应平等地获得报酬...
  • 原链接 ... Shift-left is an approach to software development where testing is performed earlier in the lifecycle—in effect, moved left ...
  • linux netem简介

    千次阅读 2013-01-11 23:52:05
    NetEM consists of two components — a tiny kernel module for a queuing discipline, and a command-line utility to configure it. The kernel module has been integrated in 2.6.8 (and 2.4.28) or later, and...
  • : Working on and completing side projects, regardless of the size of scope takes a certain level of self-discipline. The fact that you managed to put together a portfolio is a monument to your ...
  • ( Discipline ) ③ 形式方法 ( Formal Method ) ④ 过程 ( Process ) ⑤ 专业化 ( Professionalism ) 4.软件危机 解决方案 软件危机 解决方案 : 1.多种手段公用 ( 技术 + 管理 ) : ...
  • The Hacker Way

    千次阅读 2016-07-23 17:06:44
    By focusing on our mission and building great services, we believe we will create the most value for our shareholders and partners over the long term — and this in turn will enable us to keep ...
  • TSQ/CoDel队列管理以及TCP BBR如何解决Bufferbloat问题

    万次阅读 热门讨论 2017-06-03 06:21:12
    Byte queue limits work only at the device queue level, though, while the networking stack has other places—such as the queueing discipline level—where buffering can happen. So there would be value ...
  • Each zipped file may include the database files along with the data dictionary, datamapping file, and program code to create value labels. The database will be made available in multiple formats ...
  • 程序员如何学数学

    千次阅读 多人点赞 2017-08-22 04:22:22
    最近在找一些传统离散数学以外的数学书,想从其他角度补习一下计算机科学相关的数学知识,偶然间就看到一些人都推荐了这篇文章Math For Programmers,通读了一遍果然不错。但文章有点长,所以没逐字逐句地翻译,只是...
  • 关于数学和程序

    2017-09-14 21:11:26
    I’ve been working for the past 15 months on repairing my rusty math skills, ever since I read a biography of Johnny von Neumann. I’ve read a huge stack of math books, and I have an even bigger stack...
  • 本文博客地址:http://blog.csdn.net/qq1084283172/article/details/75200800一、序言在前面的博客中,已经分析过了Android Hook框架adbi源码的具体实现,Android Hook框架adbi的实现主要分为两部分,一部分是root...
  • Discipline Information (Violation) : </td> <td>".$_POST['violation']."</td> </tr> <tr> <td style='font-weight:bold'>12th Mark List : </td> <td>".$_POST...
  • 日期 内核版本 架构 作者 GitHub CSDN 2016-08-31 Linux-4.7 X86 & arm gatieme LinuxDeviceDrivers Linux内存管理 1 前景回顾前面我们讲到服务器体系(SMP, NUMA, MPP)与共享存储器架构(UMA和NUMA)1.1 UMA...
  • Handling Complexity in the Halo 2 AI

    千次阅读 2015-09-27 06:10:45
    原文:... Developers of game AI are always interested in cramming more complexity into the virtual brains they build. However
  • linux 网络协议栈-队列机制

    千次阅读 2013-09-28 11:51:04
    Queueing in the Linux Network Stack Sep 23, 2013 By  Dan Siemon ...Packet queues are a core component of any ... the driver queue, which is a simple FIFO, to the queueing discipline (QDisc) layer,...
  • Considering the current sad state of our computer programs, software development is clearly still a black art, and cannot yet be called an engineering discipline. — Bill Clinton, former President of ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,442
精华内容 976
关键字:

disciplinevalue