问:
Do Android build tools require to download Gradle for every new project?
I have a couple of Android project samples I am going to build via the commandline using <code>./gradlew build</code> on Linux. Whenever I enter this command a message says "Downloading https://services.gradle.org/distributions/gradle-3.3-all.zip". I think I already have the latest gradle under my Android Studio installation path. Why does this have to download gradle every time? Can I specify gradle as an environment variable e.g. GRADLE_HOME so that all projects can use it? </p>

答: What you have in your Android Studio installation path is not significant when using the Gradle Wrapper (gradlew). It downloads the exact version of Gradle that the current build is designed for and tested with if no other build downloaded it already. The downloaded distributions are stored under ~/.gradle/wrapper/dists/. So as long as you don't delete that folder and you have multiple builds that use the same gradle distribution in the wrapper configuration, that distribution will only be downloaded by the first build you execute. The others will use the already present distribution.

Body: I have a couple of Android project samples I am going to build via the commandline using ./gradlew build on Linux. Whenever I enter this command a message says "Downloading https://services.gradle.org/distributions/gradle-3.3-all.zip". I think I already have the latest gradle under my Android Studio installation path. Why does this have to download gradle every time? Can I specify gradle as an environment variable e.g. GRADLE_HOME so that all projects can use it?


来源: stackexchange

问:
Factors in designing Instruction set Arcitecture
What are the two majors factors to be considered while designing Instruction Set Architecture ?

I know what ISA is . But What are the factors to be considered? I already reviewed Wikipedia but it doesn't help much.

I found this as design issues for ISA.

Backward Compatibility

Are interrupts needed?

But are this two factors I am bit confused ! Please help any one ! Preparing For exams of Computer Organization and Architecture

答:
you can read full article from here
The Importance of the Design of the Instruction Set

In this chapter we will be exploring one of the most interesting and important aspects of CPU design: the design of the CPU's instruction set. The instruction set architecture (or ISA) is one of the most important design issues that a CPU designer must get right from the start. Features like caches, pipelining, superscalar implementation, etc., can all be grafted on to a CPU design long after the original design is obsolete. However, it is very difficult to change the instructions a CPU executes once the CPU is in production and people are writing software that uses those instructions. Therefore, one must carefully choose the instructions for a CPU.

You might be tempted to take the "kitchen sink" approach to instruction set design1 and include as many instructions as you can dream up in your instruction set. This approach fails for several reasons we'll discuss in the following paragraphs. Instruction set design is the epitome of compromise management. Good CPU design is the process of selecting what to throw out rather than what to leave in. It's easy enough to say "let's include everything." The hard part is deciding what to leave out once you realize you can't put everything on the chip.

Nasty reality #1: Silicon real estate. The first problem with "putting it all on the chip" is that each feature requires some number of transistors on the CPU's silicon die. CPU designers work with a "silicon budget" and are given a finite number of transistors to work with. This means that there aren't enough transistors to support "putting all the features" on a CPU. The original 8086 processor, for example, had a transistor budget of less than 30,000 transistors. The Pentium III processor had a budget of over eight million transistors. These two budgets reflect the differences in semiconductor technology in 1978 vs. 1998.

Nasty reality #2: Cost. Although it is possible to use millions of transistors on a CPU today, the more transistors you use the more expensive the CPU. Pentium IV processors, for example, cost hundreds of dollars (circa 2002). A CPU with only 30,000 transistors (also circa 2002) would cost only a few dollars. For low-cost systems it may be more important to shave some features and use fewer transistors, thus lowering the CPU's cost.

Nasty reality #3: Expandability. One problem with the "kitchen sink" approach is that it's very difficult to anticipate all the features people will want. For example, Intel's MMX and SIMD instruction enhancements were added to make multimedia programming more practical on the Pentium processor. Back in 1978 very few people could have possibly anticipated the need for these instructions.

Nasty reality #4: Legacy Support. This is almost the opposite of expandability. Often it is the case that an instruction the CPU designer feels is important turns out to be less useful than anticipated. For example, the LOOP instruction on the 80x86 CPU sees very little use in modern high-performance programs. The 80x86 ENTER instruction is another good example. When designing a CPU using the "kitchen sink" approach, it is often common to discover that programs almost never use some of the available instructions. Unfortunately, you cannot easily remove instructions in later versions of a processor because this will break some existing programs that use those instructions. Generally, once you add an instruction you have to support it forever in the instruction set. Unless very few programs use the instruction (and you're willing to let them break) or you can automatically simulate the instruction in software, removing instructions is a very difficult thing to do.

Nasty reality #4: Complexity. The popularity of a new processor is easily measured by how much software people write for that processor. Most CPU designs die a quick death because no one writes software specific to that CPU. Therefore, a CPU designer must consider the assembly programmers and compiler writers who will be using the chip upon introduction. While a "kitchen sink" approach might seem to appeal to such programmers, the truth is no one wants to learn an overly complex system. If your CPU does everything under the sun, this might appeal to someone who is already familiar with the CPU. However, pity the poor soul who doesn't know the chip and has to learn it all at once.

These problems with the "kitchen sink" approach all have a common solution: design a simple instruction set to begin with and leave room for later expansion. This is one of the main reasons the 80x86 has proven to be so popular and long-lived. Intel started with a relatively simple CPU and figured out how to extend the instruction set over the years to accommodate new features.

ContentLicense: CC BY-SA 3.0


问:
Algorithmic representation of list of list
I am creating a list with the elements of another list. I want to make sure about two things. First that the list is made from another list and second the size of list changes. Is the following representation good enough ? </p>

```<code>n ∈ {2,3,4}
new_list = [list[1], ... , list[n]]
</code>```

<p>How can I represent algorithmically that I create the "new_list" with elements of "list" without the dots ? </p>

答:
There is no standard of pseudo-code.  (I am glad there isn't.)

Standards for pseudo code?

https://cs.stackexchange.com/questions/42226/the-convention-for-declaring-arrays-in-pseudocode

Therefore, I think it is vastly up to you to imagine what is good/bad.

Here are some rough conventions, but none address what you asked directly  :-

http://www.cs.princeton.edu/courses/archive/spr11/cos116/handouts/Pseudocode_Reference.pdf

http://www.dreamincode.net/forums/topic/304088-question-in-declaring-and-using-arrays-in-writing-pseudocode/

http://cs.brown.edu/courses/cs016/static/files/docs/PseudocodeStandards.pdf

Therefore, I will use my opinion : the pseudo-code you show looks OK for me.

  Just be sure that your article uses consistent notation.

(use same symbol/pattern to denote the same thing)

I hope that this solution is good enough for you.

Body:
I am creating a list with the elements of another list. I want to make sure about two things. First that the list is made from another list and second the size of list changes. Is the following representation good enough ?

n ∈ {2,3,4}
new_list = [list[1], ... , list[n]]

How can I represent algorithmically that I create the "new_list" with elements of "list" without the dots ?


问:
reference & pointers confusing parts(declarations and their types)
I'm studying pointer and reference parts and having very hard time to study them.
I think I understand now some simple usage of reference and pointers in the function, but there is something I cannot totally understand.

Here are some variable declarations:

```<code>int a = 1;
float b = 2;
int* p = &a;
string s = "Hello";
vector<int*> values = {p};
</code>```

What will be the types of the following expressions?

```<code>&a
&b
p
&p
&s
&(s.at(1))
values.at(0)
&(values.at(0))
&values
</code>```

I have no idea what their types exactly are, but I tried it myself.

```<code>&a : pointer to int
&b : pointer float
 p : pointer to int
&p : pointer to pointer to int
&s : pointer to string
&(s.at(1)) : pointer to string
values.at(0) : pointer to int
&(values.at(0)) : pointer to pointer to int
&values : pointer to pointer to int
</code>```

and one more problem >
write the following variable declarations:
a) A pointer to a string
b) A reference to a float
c) An array of pointers-to-ints.
d) A pointer to a pointer to bool
e) A reference to a pointer to an int

and my answers are:

```<code>a: string* s = "Hello"

b: float& f = g;

c: int n =1;
   int*x =&n;
   int arr[] = {*x};

d: bool y = true;
   bool* x = &y;
   bool** qq = &x;

e: int a = 1;
   int* x = &a;
   int& z = *x;
</code>```

I'm not sure about my answers. Please help these confusing parts.

答:
&(values.at(0)) : pointer to pointer to int  OK

Why &(values.at(0)) is a pointer ?

Pointer is variable that contains address in memory
Pointer has its type

```<code>    unsigned long ip = 0xC0A80A01;  // 192.168.10.1
    unsigned char *p = (unsigned char *)&ip;
    printf("%d.%d.%d.%d\n", p[3], p[2], p[1], p[0]);
    // Result: 192.168.10.1
</code>```

I think it is only takes address of variable.

```<code>int a = 1;
int *p = &a;
&a is not a pointer
p is a pointer
</code>```

Is it?

and

int &refVar = a;
refVar is reference

Body:
I'm studying pointer and reference parts and having very hard time to study them.
I think I understand now some simple usage of reference and pointers in the function, but there is something I cannot totally understand.

Here are some variable declarations:

int a = 1;
float b = 2;
int* p = &a;
string s = "Hello";
vector<int*> values = {p};

What will be the types of the following expressions?

&a
&b
p
&p
&s
&(s.at(1))
values.at(0)
&(values.at(0))
&values

I have no idea what their types exactly are, but I tried it myself.

&a : pointer to int
&b : pointer float
 p : pointer to int
&p : pointer to pointer to int
&s : pointer to string
&(s.at(1)) : pointer to string
values.at(0) : pointer to int
&(values.at(0)) : pointer to pointer to int
&values : pointer to pointer to int

and one more problem >
write the following variable declarations:
a) A pointer to a string
b) A reference to a float
c) An array of pointers-to-ints.
d) A pointer to a pointer to bool
e) A reference to a pointer to an int

and my answers are:

a: string* s = "Hello"

b: float& f = g;

c: int n =1;
   int*x =&n;
   int arr[] = {*x};

d: bool y = true;
   bool* x = &y;
   bool** qq = &x;

e: int a = 1;
   int* x = &a;
   int& z = *x;

I'm not sure about my answers. Please help these confusing parts.

Body:
&(values.at(0)) : pointer to pointer to int  OK

Why &(values.at(0)) is a pointer ?

Pointer is variable that contains address in memory
Pointer has its type

    unsigned long ip = 0xC0A80A01;  // 192.168.10.1
    unsigned char *p = (unsigned char *)&ip;
    printf("%d.%d.%d.%d\n", p[3], p[2], p[1], p[0]);
    // Result: 192.168.10.1

I think it is only takes address of variable.

int a = 1;
int *p = &a;
&a is not a pointer
p is a pointer

Is it?

and

int &refVar = a;
refVar is reference


问:
Selenium Out of focus element
I have a scenario in selenium where I have a web element which is available on the page but to reach out to that web element sometimes we have to scroll down depending upon some business logic.
I don't want to use javascript executor and css selector. Is there any other way we can check if element is not clickable I can try to see if there is a scroll down scroller available? And my driver should scroll down and try to check that element once before it actually throw exception.</p>

答:
Let me try to answer your Questions one by one.

we have to scroll down : When you think of scroll its worth mentioning that scroll method is not a method of Webdriver, this is a method of JavaScript. JavascriptExecutor is an Interface which is available in  package org.openqa.selenium.JavascriptExecutor. Inside this Interface we have a method called executeScript() – so whatever script you will pass as a string it will be executed by JavascriptExecutor.

I don't want to use javascript executor : We are not using anything separate stuff by the name JavascriptExecutor. We are using the same instance of WebDriver i.e. driver,  but we need to downcast it so that it can act as a JavascriptExecutor to perform whatever script you will pass as a string.

css selector : Using css selector is not mandatory. Selenium provides you the flexibility to use any of the properties of a particular element available like id/name/linkText/xpath.

Let me know if this answers your Question.

Title: Selenium Out of focus element


Title: How to remove duplicate elements based date

Body:
I am having dictinoary which contains list of list

find_dup = {"one":[["1654","raj","425","16-02-2017"],["1654","mo","426","20-02-2017"],["1654","ss","425","20-02-2017"],["1654","vs","427","20-02-2017"],["1654","ss","425","14-02-2017"]]}

I want to find duplicated based in list of first and third element

eg

["1654","raj","425","16-02-2017"] -> 1654,425
["1654","mo","426","20-02-2017"] -> 1654,426
["1654","ss","425","20-02-2017"] -> 1654,425
["1654","vs","427","20-02-2017"] -> 1654,427
["1654","ss","425","14-02-2017"] -> 1654,425

From the above elements it shows 1654,425 are duplicates (since i want to find duplicates based on first and third elements)

So from the above list this list are duplicates

["1654","raj","425","16-02-2017"] -> 1654,425
["1654","ss","425","20-02-2017"] -> 1654,425
["1654","ss","425","14-02-2017"] -> 1654,425

now from this list we have to remove 2 elements which has older date (last element of list is date)

This 2 list has older date so this should be removed

["1654","raj","425","16-02-2017"] -> 1654,425
["1654","ss","425","14-02-2017"] -> 1654,425

Results should be this

find_dup = {"one":[["1654","mo","426","20-02-2017"],["1654","ss","425","20-02-2017"],["1654","vs","427","20-02-2017"]]}

I have python script which iterates through lists but i could not find logic on how to do pop an element if i find duplicate and replace the latest date

This is my script which failed

find_dup = {"one":[["1654","raj","425","16-02-2017"],["1654","mo","426","20-02-2017"],["1654","ss","425","20-02-2017"],["1654","vs","427","20-02-2017"],["1654","ss","425","14-02-2017"]]}

for d in find_dup:
    len_d = len(find_dup[d])
    store_array_dup = []
    store_array_ele = {}
    for i in find_dup[d]:

        val = i[0]+"-"+i[1]"-"+i[2]"-"+i[3]
        val_1 = i[0]+"-"+i[2]
        if val_1 in store_array_dup:
            store_array_ele.append(val_1)
        else:
            arrs = []
            arrs.append(val)
            store_array_ele[d] = arrs

How could i produce this results

find_dup = {"one":[["1654","mo","426","20-02-2017"],["1654","ss","425","20-02-2017"],["1654","vs","427","20-02-2017"]]}

Body:
First solve the problem for a list of list:

def mounarajan_no_dup(l):
    dedup = {}
    for i in l:
        k = (i[0], i[3])
        if k not in dedup:
            dedup[k] = i
        else :
            j3 = dedup[k][3]
            jdate = j3[6:10] + j3[3:5] + j3[0:2]
            i3 = i[3]
            idate = i3[6:10] + i3[3:5] + i3[0:2]
            if jdate < idate:
                dedup[k] = i
    return dedup.values()

And then apply it to every entry of find_dup.

find_dup = {
    "one":[
        ["1654","raj","425","16-02-2017"],
        ["1654","mo","426","20-02-2017"],
        ["1654","ss","425","20-02-2017"],
        ["1654","vs","427","20-02-2017"],
        ["1654","ss","425","14-02-2017"]]}
for d in find_dup:
    find_dup[d] = mounarajan_no_dup(find_dup[d])
find_dup
{'one': [['1654', 'ss', '425', '14-02-2017'], ['1654', 'raj', '425', '16-02-2017'], ['1654', 'mo', '426', '20-02-2017']]}


问:
How to fill a table with an object including an array of object in Angular2
I'm currently programming in Angular2/Typescript and I'm blocked with a table. I want to fill a table with the information I receive from my service which looks like that :

[
 {
  "id": 1,
  "serviceWindow": "24/7",
  "status": "Active",
  "customer": "BGL",
  "serviceProvidedType": "Call Desk",
  "drpContactList": [
   {
    "id": null,
    "name": "Jean Bon",
    "timeStart": "08:00",
    "timeEnd": "16:00",
    "value": "jean.bon@ctg.com",
    "mediumType": "Email"
   },
   {
    "id": null,
    "name": "Charles Degaule",
    "timeStart": "16:00",
    "timeEnd": "19:00",
    "value": "+352 258 484 494",
    "mediumType": "SMS"
   }
  ]
 },
 {
  "id": 2,
  "serviceWindow": "Week-end",
  "status": "Active",
  "customer": "POST",
  "serviceProvidedType": "Monitoring",
  "drpContactList": [
   {
    "id": null,
    "name": "Michel Palmas",
    "timeStart": "10:00",
    "timeEnd": "15:00",
    "value": "+352 658 194 191",
    "mediumType": "Phone"
   }
  ]
 },
 {
  "id": 3,
  "serviceWindow": "Business hours",
  "status": "Active",
  "customer": "ING",
  "serviceProvidedType": "Sharepoint",
  "drpContactList": [
   {
    "id": null,
    "name": "Alex Lapage",
    "timeStart": "05:00",
    "timeEnd": "10:00",
    "value": "alex.lapage@ctg.com",
    "mediumType": "Email"
   }
  ]
 },
 {
  "id": 4,
  "serviceWindow": "Manage services",
  "status": "Active",
  "customer": "DEXIA",
  "serviceProvidedType": "System Admin",
  "drpContactList": [
   {
    "id": null,
    "name": "Rémi Hirtz",
    "timeStart": "19:30",
    "timeEnd": "23:00",
    "value": "+352 595 945 154",
    "mediumType": "Phone"
   }
  ]
 },
 {
  "id": 5,
  "serviceWindow": "Enterprise holiday",
  "status": "Active",
  "customer": "POST",
  "serviceProvidedType": "Hands & Eyes",
  "drpContactList": [
   {
    "id": null,
    "name": "Thomas Jacobs",
    "timeStart": "13:00",
    "timeEnd": "18:30",
    "value": "thomas.jacbos@ctg.com",
    "mediumType": "Email"
   }
  ]
 },
 {
  "id": 6,
  "serviceWindow": "24/7",
  "status": "Active",
  "customer": "BGL",
  "serviceProvidedType": "IT Outsourcing",
  "drpContactList": [
   {
    "id": null,
    "name": "Adrien Lafonte",
    "timeStart": "05:45",
    "timeEnd": "10:30",
    "value": "+352 151 615 842",
    "mediumType": "SMS"
   }
  ]
 }
]```
</div>
</div>
</p>

<p>So there is an array of object in my principal object. How can I display the information of the second array ? I tried some tricks but I never found a good way. Here is my HTML and Typescript :</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><table class="table table-hover table-condensed">
            <th style="width:150px" align="center">Customer</th>
            <th style="width:150px" align="center">Service provided</th>
            <th style="width:150px" align="center">Service window</th>
            <th style="width:150px" align="center">DRP contact name</th>
            <th style="width:150px" align="center">Time Start</th>
            <th style="width:150px" align="center">Time End</th>
            <th style="width:150px" align="center">Medium</th>
            <th style="width:150px" align="center">DRP contact address</th>
            <th style="width:150px" align="center">Status</th>

            <tr *ngFor="#drp of drps"
                [class.selected]="drp === selectedDrp"
                (click)="gotoEdit(drp)">

                <td style="width:150px" align="center">{{drp.customer}}</td>
                <td style="width:150px" align="center">{{drp.serviceProvidedType}}</td>
                <td style="width:150px" align="center">{{drp.serviceWindow}}</td>
                <td style="width:150px" align="center">{{drp.drpContactList[0].name}}</td>
                <td style="width:150px" align="center">{{drp.drpContactList[0].timeStart}}</td>
                <td style="width:150px" align="center">{{drp.drpContactList[0].timeEnd}}</td>
                <td style="width:150px" align="center">{{drp.drpContactList[0].mediumType}}</td>
                <td style="width:150px" align="center">{{drp.drpContactList[0].value}}</td>
                <td style="width:150px" align="center">{{drp.status}}</td>
            </tr>
        </table></code>```

As you can see, for the moment I only show the first objet in the array. Either I put everything in only one row or I can create as row as object in the array.

Here is the Typescript behind everything :

export class ListDrpsComponent extends BaseComponent implements OnInit {
    drps:Drp[];

    constructor(private _drpService:DrpService,
                private messageService:MessageToUserService,
                private _router:Router) {
        super(_router, messageService);
    }

    onAddDrp() {
        let link = ['AddDrp'];
        this._router.navigate(link);
    }

    getDrps() {
        this._drpService.getDrps().subscribe(
            data => {
                this.onNext(data)
            },
            (data)=> this.onError(data),
            () => null
        );
    }

    onNext(data:Response) {
        super.onNext(data);
        this.drps = <Drp[]> data.json();
        console.log(this.drps);
    }

    ngOnInit() {
        this.getDrps();
    }

    onError(data:Response) {
        super.onError(data);
    }

    gotoEdit(drp:Drp) {
        let link = ['EditDrp', {id: drp.id}];
        this._router.navigate(link);
    }

}```

I'm sorry for the presentation of the code, I'm new here ! If you need more details, tell me, I will try to respond to your demand. And sorry for my English, it's not my native language, I'm still learning.

Cordially,

Florian

EDIT : Here is a picture of what the table looks like. I wanted to have one row per information if possible (so i should repeat the first object information as many times as there is object in the second array)

Table of DRP

答:
Without modifying your model (plnkr):</p>

```<code><ng-template ngFor let-drp [ngForOf]="drps">
    <tr *ngFor="let drpCt of drp.drpContactList"
        [class.selected]="drp === selectedDrp"
        (click)="gotoEdit(drp)">

        <td style="width:150px" align="center">{{drp.customer}}</td>
        <td style="width:150px" align="center">{{drp.serviceProvidedType}}</td>
        <td style="width:150px" align="center">{{drp.serviceWindow}}</td>

        <td style="width:150px" align="center">{{drpCt.name}}</td>
        <td style="width:150px" align="center">{{drpCt.timeStart}}</td>
        <td style="width:150px" align="center">{{drpCt.timeEnd}}</td>
        <td style="width:150px" align="center">{{drpCt.mediumType}}</td>
        <td style="width:150px" align="center">{{drpCt.value}}</td>

        <td style="width:150px" align="center">{{drp.status}}</td>
    </tr>
</ng-template>
</code>```

Body:
I'm currently programming in Angular2/Typescript and I'm blocked with a table. I want to fill a table with the information I receive from my service which looks like that :

[
 {
  "id": 1,
  "serviceWindow": "24/7",
  "status": "Active",
  "customer": "BGL",
  "serviceProvidedType": "Call Desk",
  "drpContactList": [
   {
    "id": null,
    "name": "Jean Bon",
    "timeStart": "08:00",
    "timeEnd": "16:00",
    "value": "jean.bon@ctg.com",
    "mediumType": "Email"
   },
   {
    "id": null,
    "name": "Charles Degaule",
    "timeStart": "16:00",
    "timeEnd": "19:00",
    "value": "+352 258 484 494",
    "mediumType": "SMS"
   }
  ]
 },
 {
  "id": 2,
  "serviceWindow": "Week-end",
  "status": "Active",
  "customer": "POST",
  "serviceProvidedType": "Monitoring",
  "drpContactList": [
   {
    "id": null,
    "name": "Michel Palmas",
    "timeStart": "10:00",
    "timeEnd": "15:00",
    "value": "+352 658 194 191",
    "mediumType": "Phone"
   }
  ]
 },
 {
  "id": 3,
  "serviceWindow": "Business hours",
  "status": "Active",
  "customer": "ING",
  "serviceProvidedType": "Sharepoint",
  "drpContactList": [
   {
    "id": null,
    "name": "Alex Lapage",
    "timeStart": "05:00",
    "timeEnd": "10:00",
    "value": "alex.lapage@ctg.com",
    "mediumType": "Email"
   }
  ]
 },
 {
  "id": 4,
  "serviceWindow": "Manage services",
  "status": "Active",
  "customer": "DEXIA",
  "serviceProvidedType": "System Admin",
  "drpContactList": [
   {
    "id": null,
    "name": "Rémi Hirtz",
    "timeStart": "19:30",
    "timeEnd": "23:00",
    "value": "+352 595 945 154",
    "mediumType": "Phone"
   }
  ]
 },
 {
  "id": 5,
  "serviceWindow": "Enterprise holiday",
  "status": "Active",
  "customer": "POST",
  "serviceProvidedType": "Hands & Eyes",
  "drpContactList": [
   {
    "id": null,
    "name": "Thomas Jacobs",
    "timeStart": "13:00",
    "timeEnd": "18:30",
    "value": "thomas.jacbos@ctg.com",
    "mediumType": "Email"
   }
  ]
 },
 {
  "id": 6,
  "serviceWindow": "24/7",
  "status": "Active",
  "customer": "BGL",
  "serviceProvidedType": "IT Outsourcing",
  "drpContactList": [
   {
    "id": null,
    "name": "Adrien Lafonte",
    "timeStart": "05:45",
    "timeEnd": "10:30",
    "value": "+352 151 615 842",
    "mediumType": "SMS"
   }
  ]
 }
]

So there is an array of object in my principal object. How can I display the information of the second array ? I tried some tricks but I never found a good way. Here is my HTML and Typescript :

            Customer
            Service provided
            Service window
            DRP contact name
            Time Start
            Time End
            Medium
            DRP contact address
            Status

                {{drp.customer}}
                {{drp.serviceProvidedType}}
                {{drp.serviceWindow}}
                {{drp.drpContactList[0].name}}
                {{drp.drpContactList[0].timeStart}}
                {{drp.drpContactList[0].timeEnd}}
                {{drp.drpContactList[0].mediumType}}
                {{drp.drpContactList[0].value}}
                {{drp.status}}

As you can see, for the moment I only show the first objet in the array. Either I put everything in only one row or I can create as row as object in the array.

Here is the Typescript behind everything :

export class ListDrpsComponent extends BaseComponent implements OnInit {
    drps:Drp[];

    constructor(private _drpService:DrpService,
                private messageService:MessageToUserService,
                private _router:Router) {
        super(_router, messageService);
    }

    onAddDrp() {
        let link = ['AddDrp'];
        this._router.navigate(link);
    }

    getDrps() {
        this._drpService.getDrps().subscribe(
            data => {
                this.onNext(data)
            },
            (data)=> this.onError(data),
            () => null
        );
    }

    onNext(data:Response) {
        super.onNext(data);
        this.drps = <Drp[]> data.json();
        console.log(this.drps);
    }

    ngOnInit() {
        this.getDrps();
    }

    onError(data:Response) {
        super.onError(data);
    }

    gotoEdit(drp:Drp) {
        let link = ['EditDrp', {id: drp.id}];
        this._router.navigate(link);
    }

}

I'm sorry for the presentation of the code, I'm new here ! If you need more details, tell me, I will try to respond to your demand. And sorry for my English, it's not my native language, I'm still learning.

Cordially,

Florian

EDIT : Here is a picture of what the table looks like. I wanted to have one row per information if possible (so i should repeat the first object information as many times as there is object in the second array)

Table of DRP

Body:
Without modifying your model (plnkr):

<ng-template ngFor let-drp [ngForOf]="drps">
    <tr *ngFor="let drpCt of drp.drpContactList"
        [class.selected]="drp === selectedDrp"
        (click)="gotoEdit(drp)">

        <td style="width:150px" align="center">{{drp.customer}}</td>
        <td style="width:150px" align="center">{{drp.serviceProvidedType}}</td>
        <td style="width:150px" align="center">{{drp.serviceWindow}}</td>

        <td style="width:150px" align="center">{{drpCt.name}}</td>
        <td style="width:150px" align="center">{{drpCt.timeStart}}</td>
        <td style="width:150px" align="center">{{drpCt.timeEnd}}</td>
        <td style="width:150px" align="center">{{drpCt.mediumType}}</td>
        <td style="width:150px" align="center">{{drpCt.value}}</td>

        <td style="width:150px" align="center">{{drp.status}}</td>
    </tr>
</ng-template>


问:
Not a single-group group function when I execute my SQL
I get this error when I execute my SQL, state: Not a single-group group function :

```<code>[SQL]select distinct bd.name aaa,
       substr(m.code,0,4) as mcode,
       sum(p.nassistnum) BB,
       sum(case when p.vbdef4='~' then '0' else p.vbdef4 end) CC
        from bd_material_v m
        inner join ic_purchasein_b p
           on m.pk_source=p.cmaterialvid
        inner join ic_purchasein_h h
           on  h.cgeneralhid = p.cgeneralhid and  h.ctrantypeid='1001A210000000002UW7' and h.vdef8='~'
        inner join bd_marbasclass bd
           on bd.code=substr(m.code,0,4)
        where m.creator='1001A210000000000IIQ'
      order by substr(m.code,0,4)
    --  and h.pk_org in (parameter('param3'))
                    --    and substr(h.dbilldate,1,10) >= parameter('param1')
                     --   and substr(h.dbilldate,1,10) <= parameter('param2')
[Err] ORA-00937: not a single-group group function
</code>```

The SQL is below:

```<code>select distinct bd.name aaa,
       substr(m.code,0,4) as mcode,
       sum(p.nassistnum) BB,
       sum(case when p.vbdef4='~' then '0' else p.vbdef4 end) CC
        from bd_material_v m
        inner join ic_purchasein_b p
           on m.pk_source=p.cmaterialvid
        inner join ic_purchasein_h h
           on  h.cgeneralhid = p.cgeneralhid and h.ctrantypeid='1001A210000000002UW7' and h.vdef8='~'
        inner join bd_marbasclass bd
           on bd.code=substr(m.code,0,4)
        where m.creator='1001A210000000000IIQ'
      order by substr(m.code,0,4)
</code>```

I searched Stackoverflow, but I can not find the reason of mine:

SQL not a single-group group function

答:
You should group by some columns:

```<code>....
where m.creator='1001A210000000000IIQ'
group by bd.name,
         substr(m.code,0,4)
order by substr(m.code,0,4);
</code>```

Body:
I get this error when I execute my SQL, state: Not a single-group group function :

[SQL]select distinct bd.name aaa,
       substr(m.code,0,4) as mcode,
       sum(p.nassistnum) BB,
       sum(case when p.vbdef4='~' then '0' else p.vbdef4 end) CC
        from bd_material_v m
        inner join ic_purchasein_b p
           on m.pk_source=p.cmaterialvid
        inner join ic_purchasein_h h
           on  h.cgeneralhid = p.cgeneralhid and  h.ctrantypeid='1001A210000000002UW7' and h.vdef8='~'
        inner join bd_marbasclass bd
           on bd.code=substr(m.code,0,4)
        where m.creator='1001A210000000000IIQ'
      order by substr(m.code,0,4)
    --  and h.pk_org in (parameter('param3'))
                    --    and substr(h.dbilldate,1,10) >= parameter('param1')
                     --   and substr(h.dbilldate,1,10) <= parameter('param2')
[Err] ORA-00937: not a single-group group function

The SQL is below:

select distinct bd.name aaa,
       substr(m.code,0,4) as mcode,
       sum(p.nassistnum) BB,
       sum(case when p.vbdef4='~' then '0' else p.vbdef4 end) CC
        from bd_material_v m
        inner join ic_purchasein_b p
           on m.pk_source=p.cmaterialvid
        inner join ic_purchasein_h h
           on  h.cgeneralhid = p.cgeneralhid and h.ctrantypeid='1001A210000000002UW7' and h.vdef8='~'
        inner join bd_marbasclass bd
           on bd.code=substr(m.code,0,4)
        where m.creator='1001A210000000000IIQ'
      order by substr(m.code,0,4)

I searched Stackoverflow, but I can not find the reason of mine:

SQL not a single-group group function

Body:
You should group by some columns:

....
where m.creator='1001A210000000000IIQ'
group by bd.name,
         substr(m.code,0,4)
order by substr(m.code,0,4);


问:
Command for returning index of top 3 values in a matrix.
For example there is a matrix

1 3 5
7 9 2
4 6 8

And how do I find the index of top 3 values?
In this case, it would be, (2,2), (3,3), (2,1)

What command do I have to use?

Body:
m =matrix(c(1,3,5,7,9,2,4,6,8), ncol=3, nrow=3)
top3 = tail(sort(m),4)
which(m > min(top3), arr.ind = T)


问:
Why this particular code generates "ambiguous method call" error in Android Studio?
I use iText 5 in Android Studio to create a PDF document but I get an error:

I also tried

```<code>p.add((Phrase)c);
</code>```

but I get same error :-(

How I can get rid of this error?

答:
thanks for reply - indeed I needed help regarding why 'ambiguous' appears in this context.
But now the problem is solved - this error does not appear anymore - but I don't know exactly why.
I did some Android Studio updates last week may this helped?

Thanks anyway!

Body:
I use iText 5 in Android Studio to create a PDF document but I get an error:

I also tried

p.add((Phrase)c);

but I get same error :-(

How I can get rid of this error?


问:
Compilation failure child package does not exist
I am trying to create simple Rest API app and I want to check it with jbehave framework, everything worked fine until I added dependency for image_capture project in my service_tests project.

In my code everything fine, my service_tests recognize image_capture classes but when I am trying to mvn clean install for parent app I am getting

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project service_tests: Compilation failure: Compilation failure:
 for all packages from my image_capture project.

I am using IntelliJ, java 8 and spring boot for Rest API app.

I saw many answers from stackoverflow and did not succeed with one of them.

Thanks for help in advance.

My parent pom:

```<code>        <modelVersion>4.0.0</modelVersion>
        <groupId>image_capture_parent</groupId>
        <artifactId>image_capture_parent</artifactId>
        <packaging>pom</packaging>
        <version>1.0-SNAPSHOT</version>
        <modules>
            <module>image_capture</module>
            <module>service_tests</module>
        </modules>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.1.RELEASE</version>
            <relativePath />
        </parent>
        <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.0.0.BUILD-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>

My first child project:

        <parent>
        <artifactId>image_capture_parent</artifactId>
        <groupId>image_capture_parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>image_capture</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>reserve-tomcat-port</id>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <phase>process-resources</phase>
                        <configuration>
                            <portNames>
                                <portName>tomcat.http.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

My second child project ( for running jbehave tests):

         <parent>
        <artifactId>image_capture_parent</artifactId>
        <groupId>image_capture_parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>service_tests</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>image_capture_parent</groupId>
            <artifactId>image_capture</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>20.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.jbehave/jbehave-maven-plugin -->
        <dependency>
            <groupId>org.jbehave</groupId>
            <artifactId>jbehave-maven-plugin</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20140107</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.5</version>
        </dependency>

    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>image_capture.com.Application</start-class>
        <java.version>1.8</java.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <!-- Disable unit tests -->
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.16</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jbehave</groupId>
                <artifactId>jbehave-maven-plugin</artifactId>
                <version>3.8</version>
                <executions>
                    <execution>
                        <id>run-stories-as-embeddables</id>
                        <phase>integration-test</phase>
                        <configuration>
                            <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
                            <includes>
                                <include>**/*.java</include>
                            </includes>
                            <ignoreFailureInStories>false</ignoreFailureInStories>
                            <ignoreFailureInView>false</ignoreFailureInView>
                        </configuration>
                        <goals>
                            <goal>run-stories-as-embeddables</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</code>```

答:
I found a reason: Spring Boot classes is not accessible via dependencies as I understood. That a reason that my test app does not see spring boot classes while compiling via Maven. The solution is to use additional app, not spring boot app, that has class that represents spring boot Entity class.

I found some reference in this article: https://www.toptal.com/spring/top-10-most-common-spring-framework-mistakes

The solution that I used here is a Common Mistake number 2 from the article.

Body:
I am trying to create simple Rest API app and I want to check it with jbehave framework, everything worked fine until I added dependency for image_capture project in my service_tests project.

In my code everything fine, my service_tests recognize image_capture classes but when I am trying to mvn clean install for parent app I am getting

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project service_tests: Compilation failure: Compilation failure:
 for all packages from my image_capture project.

I am using IntelliJ, java 8 and spring boot for Rest API app.

I saw many answers from stackoverflow and did not succeed with one of them.

Thanks for help in advance.

My parent pom:

        <modelVersion>4.0.0</modelVersion>
        <groupId>image_capture_parent</groupId>
        <artifactId>image_capture_parent</artifactId>
        <packaging>pom</packaging>
        <version>1.0-SNAPSHOT</version>
        <modules>
            <module>image_capture</module>
            <module>service_tests</module>
        </modules>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.1.RELEASE</version>
            <relativePath />
        </parent>
        <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.0.0.BUILD-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>

My first child project:

        <parent>
        <artifactId>image_capture_parent</artifactId>
        <groupId>image_capture_parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>image_capture</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>reserve-tomcat-port</id>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <phase>process-resources</phase>
                        <configuration>
                            <portNames>
                                <portName>tomcat.http.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>pre-integration-test</id>
                        <goals>
                            <goal>start</goal>
                        </goals>
                        <configuration>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

My second child project ( for running jbehave tests):

         <parent>
        <artifactId>image_capture_parent</artifactId>
        <groupId>image_capture_parent</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>service_tests</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>image_capture_parent</groupId>
            <artifactId>image_capture</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>20.0</version>
        </dependency>

        <dependency>
            <groupId>org.jbehave</groupId>
            <artifactId>jbehave-maven-plugin</artifactId>
            <version>3.8</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20140107</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.8.5</version>
        </dependency>

    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>image_capture.com.Application</start-class>
        <java.version>1.8</java.version>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>

                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.16</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jbehave</groupId>
                <artifactId>jbehave-maven-plugin</artifactId>
                <version>3.8</version>
                <executions>
                    <execution>
                        <id>run-stories-as-embeddables</id>
                        <phase>integration-test</phase>
                        <configuration>
                            <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
                            <includes>
                                <include>**/*.java</include>
                            </includes>
                            <ignoreFailureInStories>false</ignoreFailureInStories>
                            <ignoreFailureInView>false</ignoreFailureInView>
                        </configuration>
                        <goals>
                            <goal>run-stories-as-embeddables</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


问:
Sum of value per X grouped by Y
```<code>declare @table table (Customer  char(1), Transaction char(3), Discount float);
insert into @table values
('A', '001', '10.1'),
('A', '001', '10.1'),
('A', '002', '20.2'),
('B', '003', '30.3'),
('B', '004', '40.4')
</code>```

I am trying to do something like this:

```<code>SELECT Customer, (SELECT SUM(Discount) WHERE Transaction IS DISTINCT)
FROM @table
GROUP BY Customer
</code>```

And the result should look like:

```<code>Customer    Total Discount
--------------------------
A                   30.3
B                   70.7
</code>```

So basically I need club all the discounts for every customer per transaction, because they are sometimes repeated in my data.

答:
You can use a subquery to get only all distinct rows;

```<code>SELECT Customer, SUM(Discount) as Total_Discount FROM
(
 SELECT DISTINCT Customer, Transaction, Discount FROM @table
) x
group by Customer
</code>```

In response to your question; in case there'd be cases of same customer, same transaction, but different discount, you'd have to decide whether to treat it as a different transaction altogether, or get only the HIGHEST discount or the LOWEST discount.

For getting the highest discount,

```<code>SELECT Customer, SUM(Discount) as Total_Discount FROM
(
 SELECT Customer, Transaction, MAX(Discount) as Discount FROM @table
 GROUP BY Customer, Transaction
) x
group by Customer
</code>```

For getting the lowest discount

```<code>SELECT Customer, SUM(Discount) as Total_Discount FROM
(
 SELECT Customer, Transaction, MIN(Discount) as Discount FROM @table
 GROUP BY Customer, Transaction
) x
group by Customer
</code>```

If you're going to treat it as an entirely different transaction (meaning it'd also be added to the total) ; no need for further code change.

Title: Sum of value per X grouped by Y

Body:
declare @table table (Customer  char(1), Transaction char(3), Discount float);
insert into @table values
('A', '001', '10.1'),
('A', '001', '10.1'),
('A', '002', '20.2'),
('B', '003', '30.3'),
('B', '004', '40.4')

I am trying to do something like this:

SELECT Customer, (SELECT SUM(Discount) WHERE Transaction IS DISTINCT)
FROM @table
GROUP BY Customer

And the result should look like:

Customer    Total Discount
--------------------------
A                   30.3
B                   70.7

So basically I need club all the discounts for every customer per transaction, because they are sometimes repeated in my data.

Body:
You can use a subquery to get only all distinct rows;

SELECT Customer, SUM(Discount) as Total_Discount FROM
(
 SELECT DISTINCT Customer, Transaction, Discount FROM @table
) x
group by Customer

In response to your question; in case there'd be cases of same customer, same transaction, but different discount, you'd have to decide whether to treat it as a different transaction altogether, or get only the HIGHEST discount or the LOWEST discount.

For getting the highest discount,

SELECT Customer, SUM(Discount) as Total_Discount FROM
(
 SELECT Customer, Transaction, MAX(Discount) as Discount FROM @table
 GROUP BY Customer, Transaction
) x
group by Customer

For getting the lowest discount

SELECT Customer, SUM(Discount) as Total_Discount FROM
(
 SELECT Customer, Transaction, MIN(Discount) as Discount FROM @table
 GROUP BY Customer, Transaction
) x
group by Customer

If you're going to treat it as an entirely different transaction (meaning it'd also be added to the total) ; no need for further code change.


问:
Is there another tool out there for building oracle reports other then oracle reports builder?
I cant stand oracle reports builder. Its constantly crashing and sucking in general. Copying and pasting stuff only sometimes works. Elements visualy look selected after you unselect them. AARRRRRRRRGGHHHHHHHHHHHH!!! I need another tool. Are their any alternatives for designing the report jsps? </p>

答: Don't bother switching tools, you'll probably only be disappointed.  I've used many reporting tools and all of them have significant issues.  No matter which tool you use you'll probably end up fighting it and gradually move more and more of your logic into the database.  The more SQL tricks you learn the less you'll have to rely on poorly designed reporting tools.</p>

ContentLicense: CC BY-SA 2.5


问:
create graph with correlation matrix
I am having some problems solving this question, I have a data frame and I need to create a graph from it.

My data frame looks like :

```<code>    A =pd.DataFrame([(1, 0.3, 0.4, 0.7),
                    (0.3, 1, 0.9, 0.2),
                    (0.4, 0.9, 1, 0.1),
                    (0.7, 0.2, 0.1, 1)
                    ],  columns=['a', 'b', 'c', 'd'], index=['a', 'b', 'c', 'd'] )
    np.fill_diagonal(A.values, 0)
>>> A
     a    b    c    d
a  0.0  0.3  0.4  0.7
b  0.3  0.0  0.9  0.2
c  0.4  0.9  0.0  0.1
d  0.7  0.2  0.1  0.0
</code>```

I want to create a graph with this data. There are four nodes : a,b,c,d, and the distances between nodes are given by the matrix, for instance, distance between node a-b = 0.3  (since it is a correletaion matrix values are duplicated).

Thank you!!

I have created this function to store the values of edges as a dict (I don't know if that would be the best idea):

```<code>def edges(matr):
    edge = {}
    for m in matr.columns:
        for n in matr.index:
            a,b = m,n
            if a!= b:
                x = matr.at[m, n]
                edge[m,n] = float("{0:.4f}".format(x))
    return edge

edges(A)

>>> edges(A)
{('a', 'b'): 0.3,
 ('a', 'c'): 0.4,
 ('a', 'd'): 0.7,
 ('b', 'a'): 0.3,
 ('b', 'c'): 0.9,
 ('b', 'd'): 0.2,
 ('c', 'a'): 0.4,
 ('c', 'b'): 0.9,
 ('c', 'd'): 0.1,
 ('d', 'a'): 0.7,
 ('d', 'b'): 0.2,
 ('d', 'c'): 0.1}
</code>```

But since a-b is the same as b-a some edges are repeated, I cant figure out how to remove the repeated values.
And from that data I need to create a graph/picture.

Thank you!!

答:
There are various ways of creating a picture. I'll show graphviz.

First, your edges function adds the edges twice (from say a to b and back again), so let's just add them once.

```<code>import graphviz as gv

def edges(matr):
    edge = {}
    for m in matr.columns:
        for n in matr.index:
            a,b = m,n
            if a > b: #only add edge once
                x = matr.at[m, n]
                edge[m,n] = float("{0:.4f}".format(x))
    return edge

if __name__ == '__main__':
    A =pd.DataFrame([(1, 0.3, 0.4, 0.7),
                (0.3, 1, 0.9, 0.2),
                (0.4, 0.9, 1, 0.1),
                (0.7, 0.2, 0.1, 1)
                ],  columns=['a', 'b', 'c', 'd'], index=['a', 'b', 'c', 'd'] )
    np.fill_diagonal(A.values, 0)

    e = edges(A)
    g = gv.Graph(format="png")
    for k, v in e.iteritems():
        g.edge(k[0], k[1], len=str(v))

    print str(g)
</code>```

This gives you a graphviz format

```<code>graph {
        b -- a [len=0.3]
        c -- a [len=0.4]
        c -- b [len=0.9]
        d -- a [len=0.7]
        d -- c [len=0.1]
        d -- b [len=0.2]
}
</code>```

You could send it to the graphviz tools externally if you save it to a .dot file, e.g. dot -Tps g.dot -o g.png or do g.render('filename', view = True) in python.

Title: create graph with correlation matrix

Body:
I am having some problems solving this question, I have a data frame and I need to create a graph from it.

My data frame looks like :

    A =pd.DataFrame([(1, 0.3, 0.4, 0.7),
                    (0.3, 1, 0.9, 0.2),
                    (0.4, 0.9, 1, 0.1),
                    (0.7, 0.2, 0.1, 1)
                    ],  columns=['a', 'b', 'c', 'd'], index=['a', 'b', 'c', 'd'] )
    np.fill_diagonal(A.values, 0)
>>> A
     a    b    c    d
a  0.0  0.3  0.4  0.7
b  0.3  0.0  0.9  0.2
c  0.4  0.9  0.0  0.1
d  0.7  0.2  0.1  0.0

I want to create a graph with this data. There are four nodes : a,b,c,d, and the distances between nodes are given by the matrix, for instance, distance between node a-b = 0.3  (since it is a correletaion matrix values are duplicated).

Thank you!!

I have created this function to store the values of edges as a dict (I don't know if that would be the best idea):

def edges(matr):
    edge = {}
    for m in matr.columns:
        for n in matr.index:
            a,b = m,n
            if a!= b:
                x = matr.at[m, n]
                edge[m,n] = float("{0:.4f}".format(x))
    return edge

edges(A)

>>> edges(A)
{('a', 'b'): 0.3,
 ('a', 'c'): 0.4,
 ('a', 'd'): 0.7,
 ('b', 'a'): 0.3,
 ('b', 'c'): 0.9,
 ('b', 'd'): 0.2,
 ('c', 'a'): 0.4,
 ('c', 'b'): 0.9,
 ('c', 'd'): 0.1,
 ('d', 'a'): 0.7,
 ('d', 'b'): 0.2,
 ('d', 'c'): 0.1}

But since a-b is the same as b-a some edges are repeated, I cant figure out how to remove the repeated values.
And from that data I need to create a graph/picture.

Thank you!!

Body:
There are various ways of creating a picture. I'll show graphviz.

First, your edges function adds the edges twice (from say a to b and back again), so let's just add them once.

import graphviz as gv

def edges(matr):
    edge = {}
    for m in matr.columns:
        for n in matr.index:
            a,b = m,n
            if a > b: #only add edge once
                x = matr.at[m, n]
                edge[m,n] = float("{0:.4f}".format(x))
    return edge

if __name__ == '__main__':
    A =pd.DataFrame([(1, 0.3, 0.4, 0.7),
                (0.3, 1, 0.9, 0.2),
                (0.4, 0.9, 1, 0.1),
                (0.7, 0.2, 0.1, 1)
                ],  columns=['a', 'b', 'c', 'd'], index=['a', 'b', 'c', 'd'] )
    np.fill_diagonal(A.values, 0)

    e = edges(A)
    g = gv.Graph(format="png")
    for k, v in e.iteritems():
        g.edge(k[0], k[1], len=str(v))

    print str(g)

This gives you a graphviz format

graph {
        b -- a [len=0.3]
        c -- a [len=0.4]
        c -- b [len=0.9]
        d -- a [len=0.7]
        d -- c [len=0.1]
        d -- b [len=0.2]
}

You could send it to the graphviz tools externally if you save it to a .dot file, e.g. dot -Tps g.dot -o g.png or do g.render('filename', view = True) in python.


问:
How to create a KML file using R
I have written a R script to get some map point data (Latitude and Longitude values). I am able to plot them in R and visualize them. But now I want to generate a KML file from this data and view using Google Earth. So that I can share it with colleagues and they can see it on Google Earth too.

What is the best method / package to do this ?

答:
If you/your collegues know QGIS, this is a very good way to display data in Google Earth. QGIS has the feature of showing Google Earth as a base map and then you can open your spatial data and it will be displayed on the base map. Of course it requires your data to be correctly projected as rcs says.

Here you need to export your points as a shape file using the maptools package and Spatial Points package:

```<code>library(maptools)
library(sp)

## define projection
myProjection <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

## your points in format dataframe
coordinates.df <- as.data.frame(MyCoordinates)

## the number of points you have as dataframe
number <- as.data.frame(NumberOfPoints)

## convert points to Spatial Points Dataframe
myPoints.spdf <- SpatialPointsDataFrame(coordinates.df, number, proj4string = CRS(myProjection))

## save shapefile
writeSpatialShape(myPoints.spdf, "MyPointsName")
</code>```

Your points can now be opened in QGIS and be displayed in Google Earth. In QGIS your data can also easily be saved as kmz file if necessary.

Title: How to create a KML file using R

Body:
If you/your collegues know QGIS, this is a very good way to display data in Google Earth. QGIS has the feature of showing Google Earth as a base map and then you can open your spatial data and it will be displayed on the base map. Of course it requires your data to be correctly projected as rcs says.

Here you need to export your points as a shape file using the maptools package and Spatial Points package:

library(maptools)
library(sp)

## define projection
myProjection <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

## your points in format dataframe
coordinates.df <- as.data.frame(MyCoordinates)

## the number of points you have as dataframe
number <- as.data.frame(NumberOfPoints)

## convert points to Spatial Points Dataframe
myPoints.spdf <- SpatialPointsDataFrame(coordinates.df, number, proj4string = CRS(myProjection))

## save shapefile
writeSpatialShape(myPoints.spdf, "MyPointsName")

Your points can now be opened in QGIS and be displayed in Google Earth. In QGIS your data can also easily be saved as kmz file if necessary.


问:
Good piece of software for practicing SQL on Windows?
I brought 31 queries down to 3 for a certain page in my application by using a single join (provided by Django's ORM). Up until that very moment I thought of SQL optimization as something I didn't need to worry about. I instantly realized that there are probably so many areas that run slow which could use some SQL tomFOOlery (SQL FOO is for professionals).

Now I'm looking for a piece of open source software that will allow me to quickly create databases, and tables with a GUI, so I can quickly add data and experiment with queries. Is Access good for this (aside from not being free or open source)? Or, does Access use it's own SQL syntax?

答: There is a Firefox add-on for SQLite Database. This is a very small add-on and once done, it allows you to create database, the tables and the data visually. Pretty simple one at that.</p>


问:
Responsive CSS triangle with percents width
The code below will create an arrow right below an  element:

JSFiddle

.btn {
    position: relative;
    display: inline-block;
    width: 100px;
    height: 50px;
    text-align: center;
    color: white;
    background: gray;
    line-height: 50px;
    text-decoration: none;
}
.btn:after {
    content: "";
    position: absolute;
    bottom: -10px;
    left: 0;
    width: 0;
    height: 0;
    border-width: 10px 50px 0 50px;
    border-style: solid;
    border-color: gray transparent transparent transparent;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code>Hello!</code>```

The problem is that we have to indicate the link width to get an arrow of a proper size because we cannot indicate the border width in pixels.

How to make a responsive triangle percent based?

答:
I took @Probocop's answer and come up with the following:

```<code><style>
    .btn {
        background-color: orange;
        color: white;
        margin-bottom: 50px;
        padding: 15px;
        position: relative;
        text-align: center;
        text-decoration: none;
    }

    .btn:after {
        background-color: inherit;
        clip-path: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg"%3E%3Cdefs%3E%3CclipPath id="p" clipPathUnits="objectBoundingBox"%3E%3Cpolygon points="0 0, 1 0, 0.5 1" /%3E%3C/clipPath%3E%3C/defs%3E%3C/svg%3E#p'); /* fix for firefox (tested in version 52) */
        clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
        content: '';
        height: 50px;
        left: 0;
        position: absolute;
        right: 0;
        top: 100%;
    }
</style>

<a href="#" class="btn">Hello!</a>
</code>```

This works in Chrome and I've added a fix for Firefox. It doesn't work in Edge, however if you decrease the height of the down arrow then it doesn't look so bad.

Please note that if you are using bootstrap you will need to either change the name or override some of the styles it applies. If you decide to rename it then you also need to add the following to the .btn style:

```<code>box-sizing: content-box;
</code>```

Body:
The code below will create an arrow right below an  element:

JSFiddle

.btn {
    position: relative;
    display: inline-block;
    width: 100px;
    height: 50px;
    text-align: center;
    color: white;
    background: gray;
    line-height: 50px;
    text-decoration: none;
}
.btn:after {
    content: "";
    position: absolute;
    bottom: -10px;
    left: 0;
    width: 0;
    height: 0;
    border-width: 10px 50px 0 50px;
    border-style: solid;
    border-color: gray transparent transparent transparent;
}

Hello!

The problem is that we have to indicate the link width to get an arrow of a proper size because we cannot indicate the border width in pixels.

How to make a responsive triangle percent based?

Body:
I took @Probocop's answer and come up with the following:

<style>
    .btn {
        background-color: orange;
        color: white;
        margin-bottom: 50px;
        padding: 15px;
        position: relative;
        text-align: center;
        text-decoration: none;
    }

    .btn:after {
        background-color: inherit;
        clip-path: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg"%3E%3Cdefs%3E%3CclipPath id="p" clipPathUnits="objectBoundingBox"%3E%3Cpolygon points="0 0, 1 0, 0.5 1" /%3E%3C/clipPath%3E%3C/defs%3E%3C/svg%3E#p'); /* fix for firefox (tested in version 52) */
        clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
        content: '';
        height: 50px;
        left: 0;
        position: absolute;
        right: 0;
        top: 100%;
    }
</style>

<a href="#" class="btn">Hello!</a>

This works in Chrome and I've added a fix for Firefox. It doesn't work in Edge, however if you decrease the height of the down arrow then it doesn't look so bad.

Please note that if you are using bootstrap you will need to either change the name or override some of the styles it applies. If you decide to rename it then you also need to add the following to the .btn style:

box-sizing: content-box;


问:
Finding Minimums of all rows in a column, based on criteria, Python, Pandas
Hello Stackoverflow community!

I have attemped to find an answer to my question but without success. I am basically trying to replicate the MinIF formula from excel, but so far I have only managed to do it for "1" row at a time. Here is an example of what I am trying to achieve:

Please see attached link

The idea is, that for all products with the same subgroup, the lowest value/price for that group is found, and inserted in a new column next to it.
I hope i am being specific enough, I am relatively new to python, and I have literally no idea how to even start...

help much appreciated, thank you.

答:
I think you need transform:

```<code>df['SubGroupLowestPrice'] = df.groupby('SubGroup')['Price'].transform('min')
</code>```

Sample:

```<code>df = pd.DataFrame({'A':[1,2,3,4,5,5],
                   'SubGroup':[1,5,5,6,6,6],
                   'Price':[7,8,9,10,2,3]})

print (df)
   A  Price  SubGroup
0  1      7         1
1  2      8         5
2  3      9         5
3  4     10         6
4  5      2         6
5  5      3         6

df['SubGroupLowestPrice'] = df.groupby('SubGroup')['Price'].transform('min')
print (df)
   A  Price  SubGroup  SubGroupLowestPrice
0  1      7         1                    7
1  2      8         5                    8
2  3      9         5                    8
3  4     10         6                    2
4  5      2         6                    2
5  5      3         6                    2
</code>```

Body:
I think you need transform:

df['SubGroupLowestPrice'] = df.groupby('SubGroup')['Price'].transform('min')

Sample:

df = pd.DataFrame({'A':[1,2,3,4,5,5],
                   'SubGroup':[1,5,5,6,6,6],
                   'Price':[7,8,9,10,2,3]})

print (df)
   A  Price  SubGroup
0  1      7         1
1  2      8         5
2  3      9         5
3  4     10         6
4  5      2         6
5  5      3         6

df['SubGroupLowestPrice'] = df.groupby('SubGroup')['Price'].transform('min')
print (df)
   A  Price  SubGroup  SubGroupLowestPrice
0  1      7         1                    7
1  2      8         5                    8
2  3      9         5                    8
3  4     10         6                    2
4  5      2         6                    2
5  5      3         6                    2


问:
How to get a string from a UITextField?
How would I go about getting a string from a UITextField in the iPhone SDK? I'm trying to insert it into another concatenated string.</p>

答:
for Swift 3.0

place these lines where you need

let yourString: String = ""

yourString = textField.text

Actually text attribute of textField provide the value to String.

Title: How to get a string from a UITextField?


问:
iOS - How to handle iPhone's photos whether changed when app become active?
I use a custom UICollectionView to display iPhone's photos. I want to reload UICollectionView when app become active after user delete/modify/add one or more photos.

I save PHAsset in a array, [previousAssetsArray isEqual:currentAssetsArray] is not working.

Any idea?

EDIT:

What is the NSObject isEqual: and hash default function?

When I get photos' assets again, its address changed, so previousAsset will not equal to currentAsset even they belong to a photo. [previousAsset isEqual: currentAsset] always NO.

I also use the property hash of PHAsset to check if photos changed. But I found when I just modified(crop) one photo in Photos app, its hash not changed.

答:
try this [previousAssetsArray isEqualToArray:currentAssetsArray]

Example:: BOOL theyAreEqual = [myFirstArray isEqualToArray:mySecondArray];

if you want to compare count of both array
  previousAssetsArray.count == currentAssetsArray .count