问:
Python fsolve via data interpolation with array values
I create interpolation from data set. Then, I'd like to find values corresponding to the interpolation. I can get one value problem, but not multiple values problem, like array or matrix. It only gives me ans for the first value (8), not for all (8, 4 and 2)

```<code>#Find time becoming 80% of CA0
import numpy as np
t = np.array([0,20,40,60,120,180,300])
CA = np.array([10,8,6,5,3,2,1])

#data to interpoldation function
from scipy.interpolate import interpld
g = interpld(t, CA)

#plotting function
import matplotlib.pyplot as plt
data=g(t)
plt.plot(t, data, 'b-')
plt.show()

#this only give me an ans for the first value, 8, not for other 4 and 2?
yvalue=np.array([8,4,2])
def func(x):
    return yvalue-g(x)

initial_guess = 2
ans, = fsolve(func, initial_guess)
print(ans)
</code>```

Then, it only give me an answer only for the 1st value, not all. Anyone?

答:
The problem is that you are only providing a scalar 2 for your initial guess. When I set initial guess to an array of values, then fsolve works as expected. Specifically when I set

```<code>initial_guess = 2 * np.ones(3)
</code>```

then the ans I get is

```<code>np.array([  20.   90.  180.])
</code>```

which at a glance seems correct.

Body:
I create interpolation from data set. Then, I'd like to find values corresponding to the interpolation. I can get one value problem, but not multiple values problem, like array or matrix. It only gives me ans for the first value (8), not for all (8, 4 and 2)

#Find time becoming 80% of CA0
import numpy as np
t = np.array([0,20,40,60,120,180,300])
CA = np.array([10,8,6,5,3,2,1])

#data to interpoldation function
from scipy.interpolate import interpld
g = interpld(t, CA)

#plotting function
import matplotlib.pyplot as plt
data=g(t)
plt.plot(t, data, 'b-')
plt.show()

#this only give me an ans for the first value, 8, not for other 4 and 2?
yvalue=np.array([8,4,2])
def func(x):
    return yvalue-g(x)

initial_guess = 2
ans, = fsolve(func, initial_guess)
print(ans)

Then, it only give me an answer only for the 1st value, not all. Anyone?

Body:
The problem is that you are only providing a scalar 2 for your initial guess. When I set initial guess to an array of values, then fsolve works as expected. Specifically when I set

initial_guess = 2 * np.ones(3)

then the ans I get is

np.array([  20.   90.  180.])

which at a glance seems correct.


来源: stackexchange

问:
vb2010 - source code of website using javascript
is it possible to get the source code of a website that uses javascript using:

```<code>    Dim sourceString As String = New System.Net.WebClient().DownloadString("http://www.asx.com.au/")

    RichTextBox1.Text = sourceString
</code>```

the above code isn't getting the javascript portion, returns the following as part of the string:

```<code><noscript>Please enable JavaScript to view the page content.</noscript>
</code>```

答: Dim sourceString As String = New System.Net.WebClient().DownloadString("SomeWebPage")</p>

ContentLicense: CC BY-SA 3.0

Body:
is it possible to get the source code of a website that uses javascript using:

    Dim sourceString As String = New System.Net.WebClient().DownloadString("http://www.asx.com.au/")

    RichTextBox1.Text = sourceString

the above code isn't getting the javascript portion, returns the following as part of the string:

Please enable JavaScript to view the page content.


问:
Racket Echo Server/Client hanging
I'm trying to create a simple echo server and client in Racket.

This is the server:

```<code>(define (hello_listen port)
    (define listener (tcp-listen port))
    (define (loop)
        (define-values (in out) (tcp-accept listener))
        (thread (lambda ()
                (copy-port in out)
                (close-output-port out)))
        (loop))
    (loop))
</code>```

And this is the client:

```<code>(define (hello_socket port)
    (define-values (in out) (tcp-connect "localhost" port))
    (write "hello socket world\n" out)
    (display (read in)))
</code>```

The client does not receive any text back, and just hangs on the read.

When I write a simple client in Python however, the behavior is fine:

```<code>>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(('localhost', 9999))
>>> s.send("hi")
2
>>> s.recv(500)
'hi'
</code>```

What am I missing here in the Racket client code?

答:
There are 2 problems here:

TCP ports in Racket buffer. So in your racket script you are not actually sending the data. The easiest way to fix this is to use flush-output, but that leads to your second problem.

Your server uses copy-port, which per the docs, doesn't finish until the port closes. So you can either terminate it yourself, or have the client close it using close-output-port instead.

Which turns your client code into:

```<code>(define (hello_socket port)
  (define-values (in out) (tcp-connect "localhost" port))
  (write "hello socket world\n" out)
  (close-output-port out)
  (display (read in)))
</code>```

With this change running your client (with your server active) causes the expected behavior:

```<code>> (thread (lambda () (hello_listen 1337)))
> (hello_socket 1337)
"hello socket world\n"
</code>```

Title: Racket Echo Server/Client hanging

Body:
I'm trying to create a simple echo server and client in Racket.

This is the server:

(define (hello_listen port)
    (define listener (tcp-listen port))
    (define (loop)
        (define-values (in out) (tcp-accept listener))
        (thread (lambda ()
                (copy-port in out)
                (close-output-port out)))
        (loop))
    (loop))

And this is the client:

(define (hello_socket port)
    (define-values (in out) (tcp-connect "localhost" port))
    (write "hello socket world\n" out)
    (display (read in)))

The client does not receive any text back, and just hangs on the read.

When I write a simple client in Python however, the behavior is fine:

>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(('localhost', 9999))
>>> s.send("hi")
2
>>> s.recv(500)
'hi'

What am I missing here in the Racket client code?

Body:
There are 2 problems here:

TCP ports in Racket buffer. So in your racket script you are not actually sending the data. The easiest way to fix this is to use flush-output, but that leads to your second problem.

Your server uses copy-port, which per the docs, doesn't finish until the port closes. So you can either terminate it yourself, or have the client close it using close-output-port instead.

Which turns your client code into:

(define (hello_socket port)
  (define-values (in out) (tcp-connect "localhost" port))
  (write "hello socket world\n" out)
  (close-output-port out)
  (display (read in)))

With this change running your client (with your server active) causes the expected behavior:

> (thread (lambda () (hello_listen 1337)))
> (hello_socket 1337)
"hello socket world\n"


问:
how to config nginx docker container to recognize localhost application in different port?
Setup:
All following are running on my Mac OS:

localhost:8089 a nodejs REST api runing in my local, OUTSIDE of the nginx container, stand alone!

locahost:80 nginx docker container

I was able to serve static file inside the nginx docker container, but when I set the config for the nginx as:

```<code>http {
    server {
        location / {
            root /usr/share/nginx/html;
        }
        location /api/ {
            proxy_pass http://localhost:8089;
        }
    }
}
</code>```

for some reason, any localhost:80/api call that suppose to direct to http://localhost:8089; call is returning 404 not found page

```<code>404 Not Found

nginx/1.13.6
</code>```

Any idea where is the config I made wrong? I feel like maybe I shouldn't use localhost:8089 inside nginx? But then what should I be using?

An example can be found here
https://github.com/adamchenwei/docker-nginx-playground

答:
Containers have their own networking namespace / networking stack. So localhost inside the container is the localhost of the container itself.

If you are running Docker for Mac, there is a special hostname that's available inside the container that allows you to connect to services that are running on the host itself. Refer to this answer for more information; https://stackoverflow.com/a/43541732/1811501

If you are running Docker on Linux, this answer (on the same question) allows you to find the IP-address to connect to; https://stackoverflow.com/a/31328031/1811501

Body:
Setup:
All following are running on my Mac OS:

localhost:8089 a nodejs REST api runing in my local, OUTSIDE of the nginx container, stand alone!

locahost:80 nginx docker container

I was able to serve static file inside the nginx docker container, but when I set the config for the nginx as:

http {
    server {
        location / {
            root /usr/share/nginx/html;
        }
        location /api/ {
            proxy_pass http://localhost:8089;
        }
    }
}

for some reason, any localhost:80/api call that suppose to direct to http://localhost:8089; call is returning 404 not found page

404 Not Found

nginx/1.13.6

Any idea where is the config I made wrong? I feel like maybe I shouldn't use localhost:8089 inside nginx? But then what should I be using?

An example can be found here
https://github.com/adamchenwei/docker-nginx-playground


问:
Linq Join With Include Statement
```<code>IQueryable<Employee> emps = CreateObjectSet<Employee>()
                                  .Include(u => u.Departments)
                                  .AsQueryable();
IQueryable<Products> prods = CreateObjectSet<Products>().AsQueryable();
</code>```

CreateObjectSet is ObjectContext's CreateObjectSetMethod

```<code>        return (from emp in emps
                join prod in prods
                on emp.ProductID equals prod.ProductID
                where emp.EmployeeID == 10
                select employee).ToList();
</code>```

The problem is from  the first line, i use the include statement and include departments with the employees the return values does not have departments with as they are never included. Kindly suggest something.

This is just a demo query, actual query is far complex, so please don't suggest that i should not go with the join statement, but simple include and where clause, that does not serve me ni my scenario.

Thanks

答:
This can be solved with the following code:</p>

```<code>var query = from emp in emps
            join prod in prods
            on emp.ProductID equals prod.ProductID
            where emp.EmployeeID == 10
            select employee;
var result = query.Include(u => u.Departments)
</code>```

Title: Linq Join With Include Statement

Body:
IQueryable<Employee> emps = CreateObjectSet<Employee>()
                                  .Include(u => u.Departments)
                                  .AsQueryable();
IQueryable<Products> prods = CreateObjectSet<Products>().AsQueryable();

CreateObjectSet is ObjectContext's CreateObjectSetMethod

        return (from emp in emps
                join prod in prods
                on emp.ProductID equals prod.ProductID
                where emp.EmployeeID == 10
                select employee).ToList();

The problem is from  the first line, i use the include statement and include departments with the employees the return values does not have departments with as they are never included. Kindly suggest something.

This is just a demo query, actual query is far complex, so please don't suggest that i should not go with the join statement, but simple include and where clause, that does not serve me ni my scenario.

Thanks

Body:
This can be solved with the following code:

var query = from emp in emps
            join prod in prods
            on emp.ProductID equals prod.ProductID
            where emp.EmployeeID == 10
            select employee;
var result = query.Include(u => u.Departments)


问:
producing related 'detail' for a summary query
Data:

```<code>ID          CITY         SEX            AGE
1           NYC          M              23
2           NYC          M              28
3           NYC          F              22
4           NYC          F              19
5           LA           M              29
6           LA           M              25
7           LA           F              18
8           LA           F              21
</code>```

Query: I want to produce the ID of the youngest person for each gender from each city. There are 2 genders, and 2 cities in the data above (although there may be more cities in the actual data).

I want to solve this using both Microsoft Access as well as plain SQL

Below is my solution using Microsoft Access. Do you know a better
solution?

I don't know how to do this with plain SQL. What is your solution?

Data (in Access)

Query 1 (used by Query 2)

Query 2 (uses Query 1, and produces the IDs that I was looking for)

Body:
Data:

ID          CITY         SEX            AGE
1           NYC          M              23
2           NYC          M              28
3           NYC          F              22
4           NYC          F              19
5           LA           M              29
6           LA           M              25
7           LA           F              18
8           LA           F              21

Query: I want to produce the ID of the youngest person for each gender from each city. There are 2 genders, and 2 cities in the data above (although there may be more cities in the actual data).

I want to solve this using both Microsoft Access as well as plain SQL

Below is my solution using Microsoft Access. Do you know a better
solution?

I don't know how to do this with plain SQL. What is your solution?

Data (in Access)

Query 1 (used by Query 2)

Query 2 (uses Query 1, and produces the IDs that I was looking for)

Body:
Use correlated query:

SELECT *
FROM table1 t1
WHERE t1.age =
    ( SELECT min(t2.age)
     FROM table1 t2
     WHERE t1.city = t2.city
       AND t1.sex = t2.sex )

Result:

+----+------+-----+-----+
| id | city | sex | age |
+----+------+-----+-----+
|  1 | NYC  | M   |  23 |
|  4 | NYC  | F   |  19 |
|  6 | LA   | M   |  25 |
|  7 | LA   | F   |  18 |
+----+------+-----+-----+

DEMO


问:
How to get all possibilities of adding two indexes inside an infinite array in c++
Ok so I am learning c++ and I got stumped with this in the language. Ok so say I have an infinite list ,and I want to figure out all the possible additions with it. EX [1,2,3]   = 1 +2, 1+3, 2+1, 2+3, 3+1, 3+2.... and it would be with a list that would be so huge that I wouldn't be able to put every specific index into there.
Here were I ideas I was thinking ,but didn't work

```<code>bool sum(){
int b[] = {1, 5, 3, 9};
int n;
int equation;
    for(n = 0; n < 4; ++n){
        equation = Array[n] + Array [n+1 || n +2 || n+3 || n+4];
    if(equation == 10){
        return true;
}

   }
    return false;
    }
</code>```

I swear if feels like I am missing an equation or it's something right under my nose.

答:
In this situation, you want to use a nested for loop.

The logic goes as follows: for every element in b, also check every element in b, and see if the sum adds up to 10.

```<code>for (size_t i = 0; i < sizeof(b); ++i){ //.length returns syntax error with //arrays
    for (size_t j = 0; j < sizeof(b); ++j){// same as previously stated
        if (i == j) continue;    //So that you don't add the number to itself

        if (b[i] + b[j] == 10){
            return true;
        }
    }
}
return false
</code>```

Output:

```<code>1
</code>```

we know one is true so we know this solves the problem

Body:
Ok so I am learning c++ and I got stumped with this in the language. Ok so say I have an infinite list ,and I want to figure out all the possible additions with it. EX [1,2,3]   = 1 +2, 1+3, 2+1, 2+3, 3+1, 3+2.... and it would be with a list that would be so huge that I wouldn't be able to put every specific index into there.
Here were I ideas I was thinking ,but didn't work

bool sum(){
int b[] = {1, 5, 3, 9};
int n;
int equation;
    for(n = 0; n < 4; ++n){
        equation = Array[n] + Array [n+1 || n +2 || n+3 || n+4];
    if(equation == 10){
        return true;
}

   }
    return false;
    }

I swear if feels like I am missing an equation or it's something right under my nose.

Body:
In this situation, you want to use a nested for loop.

The logic goes as follows: for every element in b, also check every element in b, and see if the sum adds up to 10.

for (size_t i = 0; i < sizeof(b); ++i){ //.length returns syntax error with //arrays
    for (size_t j = 0; j < sizeof(b); ++j){// same as previously stated
        if (i == j) continue;    //So that you don't add the number to itself

        if (b[i] + b[j] == 10){
            return true;
        }
    }
}
return false

Output:

1

we know one is true so we know this solves the problem


问:
No provider for NavController! Ionic 3
I'm Using Ionic3 for my university project , I had added setting parts of my app.html and trying to link (click)="home()" but it's not working for me.

I got following error

Error: No provider for NavController!
      at injectionError (http://localhost:8100/build/vendor.js:1527:90)
      at noProviderError (http://localhost:8100/build/vendor.js:1565:12)
      at ReflectiveInjector_.throwOrNull (http://localhost:8100/build/vendor.js:3007:19)
      at ReflectiveInjector.getByKeyDefault (http://localhost:8100/build/vendor.js:3046:25)
      at ReflectiveInjector.getByKey (http://localhost:8100/build/vendor.js:2978:25)
      at ReflectiveInjector.get (http://localhost:8100/build/vendor.js:2847:21)
      at resolveNgModuleDep (http://localhost:8100/build/vendor.js:9847:25)
      at NgModuleRef_.get (http://localhost:8100/build/vendor.js:10935:16)
      at resolveDep (http://localhost:8100/build/vendor.js:11438:45)
      at createClass (http://localhost:8100/build/vendor.js:11302:32)

app.html

```<code><!--------------------------------------Main Navigation--------------------------->

<ion-menu id="myMenu" [content]="content" side="right" persistent="true" [class]="selectedTheme">
  <ion-header>
    <ion-toolbar>
      <ion-grid>

        <ion-row>
          <ion-col col-6>
            <div text-left style="" class="app-listname">
              Project</div>
          </ion-col>
          <ion-col  (click)="home()">
            <div class="tether-setting" style="text-align: right;font-size: 2rem; color:#a57958;">
              <ion-icon ios="ios-settings-outline" md="md-settings"></ion-icon>
            </div>

          </ion-col>
          <ion-col>
            <div class="tether-logout" style="font-size: 2rem; color:#a57958; text-indent: 0rem;  text-align: right;">
              <ion-icon ios="ios-log-out" md="md-log-out"></ion-icon>
            </div>
          </ion-col>
        </ion-row>
      </ion-grid>

    </ion-toolbar>
  </ion-header>

  <ion-content>
    <div class="ion-tm">
      <ion-list>
        <button menuClose ion-item *ngFor="let p of pages" [class.activeHighlight]="checkActive(p)" (click)="openPage(p)">
          <ion-icon [name]="p.icon" item-left></ion-icon>{{p.title}}</button>

      </ion-list>
    </div>
  </ion-content>

</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false" [class]="selectedTheme"></ion-nav>
<!--------------------------------------Main Navigation--------------------------->
</code>```

app.component.ts

```<code>   import {Component, ViewChild} from '@angular/core';
import {Nav, Platform,NavController} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';

import {HomePage} from '../pages/home/home';

import {SettingsPage} from "../pages/settings/settings";
import {HelpPage} from "../pages/help/help";

import {UserloginslidePage} from "../pages/userloginslide/userloginslide";
import {SettingsProvider} from "../providers/settings/settings";
import {ModalPage} from "../pages/modal/modal";
@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  @ViewChild(Nav) nav: Nav;
  rootPage: any = UserloginPage;
  selectedTheme: String;  //Themeoption
  activepage: any;
  pages: Array<{ title: string, component: any, icon: string }>;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider,private navCtrl: NavController) {
    this.settings.getActiveTheme().subscribe(val => this.selectedTheme = val);  //Themeoption

    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
    });

    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });

    this.pages = [

      {title: 'Dashboard', component: HomePage, icon: "ios-home-outline"},

      {title: 'Settings', component: SettingsPage, icon: "ios-settings-outline"},
      {title: 'Help', component: HelpPage, icon: "ios-help-circle-outline"},
      {title: '  User loginslide ', component:UserloginslidePage, icon: "ios-contact-outline"},

    ];

    this.activepage = this.pages[0];
  }

  //Themeoption
  openPage(page) {

    this.nav.setRoot(page.component);
    this.activepage = page;

  }
  checkActive(page) {
    return page == this.activepage;
  }

  home(){
    this.navCtrl.push(HomePage);
  }
}
</code>```

答:
As you can see in the ionic api docs, you have to load the NavController in the constructor:

constructor(private navCtrl: NavController) {}

Title: No provider for NavController! Ionic 3

Body:
I'm Using Ionic3 for my university project , I had added setting parts of my app.html and trying to link (click)="home()" but it's not working for me.

I got following error

Error: No provider for NavController!
      at injectionError (http://localhost:8100/build/vendor.js:1527:90)
      at noProviderError (http://localhost:8100/build/vendor.js:1565:12)
      at ReflectiveInjector_.throwOrNull (http://localhost:8100/build/vendor.js:3007:19)
      at ReflectiveInjector.getByKeyDefault (http://localhost:8100/build/vendor.js:3046:25)
      at ReflectiveInjector.getByKey (http://localhost:8100/build/vendor.js:2978:25)
      at ReflectiveInjector.get (http://localhost:8100/build/vendor.js:2847:21)
      at resolveNgModuleDep (http://localhost:8100/build/vendor.js:9847:25)
      at NgModuleRef_.get (http://localhost:8100/build/vendor.js:10935:16)
      at resolveDep (http://localhost:8100/build/vendor.js:11438:45)
      at createClass (http://localhost:8100/build/vendor.js:11302:32)

app.html

<ion-menu id="myMenu" [content]="content" side="right" persistent="true" [class]="selectedTheme">
  <ion-header>
    <ion-toolbar>
      <ion-grid>

        <ion-row>
          <ion-col col-6>

              Project

          </ion-col>
          <ion-col  (click)="home()">

              <ion-icon ios="ios-settings-outline" md="md-settings"></ion-icon>

          </ion-col>
          <ion-col>

              <ion-icon ios="ios-log-out" md="md-log-out"></ion-icon>

          </ion-col>
        </ion-row>
      </ion-grid>

    </ion-toolbar>
  </ion-header>

  <ion-content>

      <ion-list>
        <button menuClose ion-item *ngFor="let p of pages" [class.activeHighlight]="checkActive(p)" (click)="openPage(p)">
          <ion-icon [name]="p.icon" item-left></ion-icon>{{p.title}}</button>

      </ion-list>

  </ion-content>

</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false" [class]="selectedTheme"></ion-nav>

app.component.ts

   import {Component, ViewChild} from '@angular/core';
import {Nav, Platform,NavController} from 'ionic-angular';
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';

import {HomePage} from '../pages/home/home';

import {SettingsPage} from "../pages/settings/settings";
import {HelpPage} from "../pages/help/help";

import {UserloginslidePage} from "../pages/userloginslide/userloginslide";
import {SettingsProvider} from "../providers/settings/settings";
import {ModalPage} from "../pages/modal/modal";
@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  @ViewChild(Nav) nav: Nav;
  rootPage: any = UserloginPage;
  selectedTheme: String;  //Themeoption
  activepage: any;
  pages: Array<{ title: string, component: any, icon: string }>;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,private settings: SettingsProvider,private navCtrl: NavController) {
    this.settings.getActiveTheme().subscribe(val => this.selectedTheme = val);  //Themeoption

    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
    });

    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      statusBar.styleDefault();
      splashScreen.hide();
    });

    this.pages = [

      {title: 'Dashboard', component: HomePage, icon: "ios-home-outline"},

      {title: 'Settings', component: SettingsPage, icon: "ios-settings-outline"},
      {title: 'Help', component: HelpPage, icon: "ios-help-circle-outline"},
      {title: '  User loginslide ', component:UserloginslidePage, icon: "ios-contact-outline"},

    ];

    this.activepage = this.pages[0];
  }

  //Themeoption
  openPage(page) {

    this.nav.setRoot(page.component);
    this.activepage = page;

  }
  checkActive(page) {
    return page == this.activepage;
  }

  home(){
    this.navCtrl.push(HomePage);
  }
}


问:
Right way to Plot Dynamic Grouped Bar chart.js
I have the following data which should be shown in a grouped bar chart using chart.js:

Average delivery days on the left side

Week names at the bottom

The route names beside each other per week name

My json data(not all data are here):

```<code>    {"data":[{"RouteID":"MK","week_name":"2016 Week 2","Average_Delivery_Days":1},{"RouteID":"TSM","week_name":"2016 Week 2","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 3","Average_Delivery_Days":1},{"RouteID":"CAV","week_name":"2016 Week 4","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 4","Average_Delivery_Days":1},{"RouteID":"PQU","week_name":"2016 Week 4","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 5","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 5","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 5","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 5","Average_Delivery_Days":1},{"RouteID":"PQU","week_name":"2016 Week 5","Average_Delivery_Days":1},{"RouteID":"CAV","week_name":"2016 Week 6","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 6","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 6","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 6","Average_Delivery_Days":1},{"RouteID":"TSM","week_name":"2016 Week 6","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 7","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 7","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 7","Average_Delivery_Days":1},{"RouteID":"PQU","week_name":"2016 Week 7","Average_Delivery_Days":1},{"RouteID":"TSM","week_name":"2016 Week 7","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 8","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 8","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 8","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 8","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 8","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 9","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 9","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 9","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 9","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 9","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 10","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 10","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 10","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 10","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 10","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 11","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 11","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 11","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 11","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 11","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 12","Average_Delivery_Days":4},{"RouteID":"C","week_name":"2016 Week 12","Average_Delivery_Days":4},{"RouteID":"CAV","week_name":"2016 Week 12","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 12","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 12","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 13","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 13","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 13","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 13","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 13","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 14","Average_Delivery_Days":5},{"RouteID":"MK","week_name":"2016 Week 14","Average_Delivery_Days":4},{"RouteID":"C","week_name":"2016 Week 14","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2016 Week 14","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 14","Average_Delivery_Days":3},{"RouteID":"MK","week_name":"2016 Week 15","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2016 Week 15","Average_Delivery_Days":3},{"RouteID":"C","week_name":"2016 Week 15","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 15","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 15","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 16","Average_Delivery_Days":5},{"RouteID":"TSM","week_name":"2016 Week 16","Average_Delivery_Days":3},{"RouteID":"MK","week_name":"2016 Week 16","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 16","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 16","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 17","Average_Delivery_Days":5},{"RouteID":"MK","week_name":"2016 Week 17","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2016 Week 17","Average_Delivery_Days":4},{"RouteID":"C","week_name":"2016 Week 17","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 17","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 18","Average_Delivery_Days":4},{"RouteID":"C","week_name":"2016 Week 18","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 18","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 18","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 18","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 19","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2016 Week 19","Average_Delivery_Days":3},{"RouteID":"MK","week_name":"2016 Week 19","Average_Delivery_Days":3},{"RouteID":"C","week_name":"2016 Week 19","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 19","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 20","Average_Delivery_Days":4},{"RouteID":"CAV","week_name":"2016 Week 20","Average_Delivery_Days":4},{"RouteID":"TSM","week_name":"2016 Week 20","Average_Delivery_Days":4},{"RouteID":"MK","week_name":"2016 Week 20","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 20","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 21","Average_Delivery_Days":4},{"RouteID":"TSM","week_name":"2016 Week 21","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 21","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 21","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 21","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 22","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 22","Average_Delivery_Days":3},{"RouteID":"MK","week_name":"2016 Week 22","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 22","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 22","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 23","Average_Delivery_Days":19},{"RouteID":"TSM","week_name":"2016 Week 23","Average_Delivery_Days":4},{"RouteID":"C","week_name":"2016 Week 23","Average_Delivery_Days":4},{"RouteID":"CAV","week_name":"2016 Week 23","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 23","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 24","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 24","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 24","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 24","Average_Delivery_Days":1},{"RouteID":"PQU","week_name":"2016 Week 24","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 25","Average_Delivery_Days":5},{"RouteID":"CAV","week_name":"2016 Week 25","Average_Delivery_Days":3},{"RouteID":"MK","week_name":"2016 Week 25","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 25","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 25","Average_Delivery_Days":1},{"RouteID":"CAV","week_name":"2016 Week 26","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2016 Week 26","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 26","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 26","Average_Delivery_Days":1},{"RouteID":"TSM","week_name":"2016 Week 26","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 27","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 27","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 27","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 27","Average_Delivery_Days":1},{"RouteID":"PQU","week_name":"2016 Week 27","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 28","Average_Delivery_Days":4},{"RouteID":"TSM","week_name":"2016 Week 28","Average_Delivery_Days":4},{"RouteID":"MK","week_name":"2016 Week 28","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 28","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 28","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 29","Average_Delivery_Days":5},{"RouteID":"PQU","week_name":"2016 Week 29","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 29","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 29","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 29","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 30","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 30","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 30","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 30","Average_Delivery_Days":1},{"RouteID":"CAV","week_name":"2016 Week 30","Average_Delivery_Days":1},{"RouteID":"CAV","week_name":"2017 Week 48","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2017 Week 48","Average_Delivery_Days":3},{"RouteID":"C","week_name":"2017 Week 48","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2017 Week 48","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2017 Week 49","Average_Delivery_Days":10},{"RouteID":"CAV","week_name":"2017 Week 49","Average_Delivery_Days":4},{"RouteID":"TSM","week_name":"2017 Week 49","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2017 Week 49","Average_Delivery_Days":1}],"filter_by":"Weekly"}
</code>```

But I just can't get it right since based on my understanding, the route names should be the column names in order to make it right.

Wrong Graph:

Right Graph:

And my sample query:

```<code>SELECT [RouteID],
CAST(DATEPART(YEAR,[DeliveryDate]) as varchar) + ' Week ' + CAST(DATEPART(WEEK,[DeliveryDate]) AS varchar) AS week_name,
AVG(DATEDIFF(day, CONVERT(date, [UnloadDate]), CONVERT(date, [DeliveryDate]))) as Average_Delivery_Days
FROM [CARGODB].[dbo].[Cargo_Transactions]
WHERE [DeliveryDate] IS NOT NULL AND [DeliveryDate] != 0
AND CONVERT(date, [DeliveryDate]) BETWEEN '2016-01-01' AND GETDATE()
AND [UnloadDate] IS NOT NULL AND [UnloadDate] != 0 AND [DeliveryDate] > [UnloadDate]
AND [Deleted] = 0 and [StageID] = 'D' AND [RouteID] IN ('TSM', 'C', 'MK', 'CAV', 'PQU')
GROUP BY DATEPART(YEAR,[DeliveryDate]), DATEPART(WEEK,[DeliveryDate]), [RouteID]
ORDER BY DATEPART(YEAR,[DeliveryDate]), DATEPART(WEEK,[DeliveryDate]), Average_Delivery_Days desc
</code>```

My Chart.js Code:

```<code>var date_created = [];
        var average_delivery_days = [];
        var route_name = [];
        var oss_new_customers = [];

        for(var i in data.data) {
            date_created.push(data.data[i]['week_name']);
            average_delivery_days.push(data.data[i]['Average_Delivery_Days']);
            route_name.push(data.data[i]['RouteID']);
        }

        var chartdata = {
            labels: date_created,
            datasets : [
                {
                    label: route_name,
                    backgroundColor: 'rgba(52, 152, 219,1.0)',
                    data: average_delivery_days,
                    legend: {
                        onClick: function(e){
                            hidden:true
                        }
                    }
                }
            ]
        };

        ctx = $("#delivery_performance_chart");
        delivery_performance_barGraph = new Chart(ctx, {
            type: 'bar',
            data: chartdata,
            options: {
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero:true
                        }
                    }]
                },
                tooltips: {
                    mode: 'index',
                    footerFontStyle: 'normal'
                },
                hover: {
                    mode: 'index',
                    intersect: true
                },
                scales: {
                    xAxes: [{
                        display: true,
                        scaleLabel: {
                            show: true
                        }
                    }],
                    yAxes: [{
                        display: true,
                        scaleLabel: {
                            show: true
                        }
                    }]
                },
                maintainAspectRatio: false,
                responsive:true
            }
        });
</code>```

Your help is highly appreciated. Thanks!

答: So for everyone who somehow encountered the same issue, here's the link on where I got the answer. :)</p>

Body:
I have the following data which should be shown in a grouped bar chart using chart.js:

Average delivery days on the left side

Week names at the bottom

The route names beside each other per week name

My json data(not all data are here):

    {"data":[{"RouteID":"MK","week_name":"2016 Week 2","Average_Delivery_Days":1},{"RouteID":"TSM","week_name":"2016 Week 2","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 3","Average_Delivery_Days":1},{"RouteID":"CAV","week_name":"2016 Week 4","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 4","Average_Delivery_Days":1},{"RouteID":"PQU","week_name":"2016 Week 4","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 5","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 5","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 5","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 5","Average_Delivery_Days":1},{"RouteID":"PQU","week_name":"2016 Week 5","Average_Delivery_Days":1},{"RouteID":"CAV","week_name":"2016 Week 6","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 6","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 6","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 6","Average_Delivery_Days":1},{"RouteID":"TSM","week_name":"2016 Week 6","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 7","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 7","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 7","Average_Delivery_Days":1},{"RouteID":"PQU","week_name":"2016 Week 7","Average_Delivery_Days":1},{"RouteID":"TSM","week_name":"2016 Week 7","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 8","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 8","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 8","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 8","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 8","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 9","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 9","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 9","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 9","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 9","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 10","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 10","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 10","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 10","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 10","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 11","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 11","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 11","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 11","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 11","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 12","Average_Delivery_Days":4},{"RouteID":"C","week_name":"2016 Week 12","Average_Delivery_Days":4},{"RouteID":"CAV","week_name":"2016 Week 12","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 12","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 12","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 13","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 13","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 13","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 13","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 13","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 14","Average_Delivery_Days":5},{"RouteID":"MK","week_name":"2016 Week 14","Average_Delivery_Days":4},{"RouteID":"C","week_name":"2016 Week 14","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2016 Week 14","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 14","Average_Delivery_Days":3},{"RouteID":"MK","week_name":"2016 Week 15","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2016 Week 15","Average_Delivery_Days":3},{"RouteID":"C","week_name":"2016 Week 15","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 15","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 15","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 16","Average_Delivery_Days":5},{"RouteID":"TSM","week_name":"2016 Week 16","Average_Delivery_Days":3},{"RouteID":"MK","week_name":"2016 Week 16","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 16","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 16","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 17","Average_Delivery_Days":5},{"RouteID":"MK","week_name":"2016 Week 17","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2016 Week 17","Average_Delivery_Days":4},{"RouteID":"C","week_name":"2016 Week 17","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 17","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 18","Average_Delivery_Days":4},{"RouteID":"C","week_name":"2016 Week 18","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 18","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 18","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 18","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 19","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2016 Week 19","Average_Delivery_Days":3},{"RouteID":"MK","week_name":"2016 Week 19","Average_Delivery_Days":3},{"RouteID":"C","week_name":"2016 Week 19","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 19","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 20","Average_Delivery_Days":4},{"RouteID":"CAV","week_name":"2016 Week 20","Average_Delivery_Days":4},{"RouteID":"TSM","week_name":"2016 Week 20","Average_Delivery_Days":4},{"RouteID":"MK","week_name":"2016 Week 20","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 20","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 21","Average_Delivery_Days":4},{"RouteID":"TSM","week_name":"2016 Week 21","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 21","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 21","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 21","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 22","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 22","Average_Delivery_Days":3},{"RouteID":"MK","week_name":"2016 Week 22","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 22","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 22","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 23","Average_Delivery_Days":19},{"RouteID":"TSM","week_name":"2016 Week 23","Average_Delivery_Days":4},{"RouteID":"C","week_name":"2016 Week 23","Average_Delivery_Days":4},{"RouteID":"CAV","week_name":"2016 Week 23","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 23","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 24","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 24","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 24","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 24","Average_Delivery_Days":1},{"RouteID":"PQU","week_name":"2016 Week 24","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 25","Average_Delivery_Days":5},{"RouteID":"CAV","week_name":"2016 Week 25","Average_Delivery_Days":3},{"RouteID":"MK","week_name":"2016 Week 25","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 25","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 25","Average_Delivery_Days":1},{"RouteID":"CAV","week_name":"2016 Week 26","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2016 Week 26","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 26","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 26","Average_Delivery_Days":1},{"RouteID":"TSM","week_name":"2016 Week 26","Average_Delivery_Days":1},{"RouteID":"MK","week_name":"2016 Week 27","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 27","Average_Delivery_Days":2},{"RouteID":"CAV","week_name":"2016 Week 27","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 27","Average_Delivery_Days":1},{"RouteID":"PQU","week_name":"2016 Week 27","Average_Delivery_Days":1},{"RouteID":"C","week_name":"2016 Week 28","Average_Delivery_Days":4},{"RouteID":"TSM","week_name":"2016 Week 28","Average_Delivery_Days":4},{"RouteID":"MK","week_name":"2016 Week 28","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 28","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2016 Week 28","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 29","Average_Delivery_Days":5},{"RouteID":"PQU","week_name":"2016 Week 29","Average_Delivery_Days":3},{"RouteID":"CAV","week_name":"2016 Week 29","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2016 Week 29","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 29","Average_Delivery_Days":2},{"RouteID":"TSM","week_name":"2016 Week 30","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2016 Week 30","Average_Delivery_Days":2},{"RouteID":"PQU","week_name":"2016 Week 30","Average_Delivery_Days":2},{"RouteID":"C","week_name":"2016 Week 30","Average_Delivery_Days":1},{"RouteID":"CAV","week_name":"2016 Week 30","Average_Delivery_Days":1},{"RouteID":"CAV","week_name":"2017 Week 48","Average_Delivery_Days":4},{"RouteID":"PQU","week_name":"2017 Week 48","Average_Delivery_Days":3},{"RouteID":"C","week_name":"2017 Week 48","Average_Delivery_Days":3},{"RouteID":"TSM","week_name":"2017 Week 48","Average_Delivery_Days":3},{"RouteID":"PQU","week_name":"2017 Week 49","Average_Delivery_Days":10},{"RouteID":"CAV","week_name":"2017 Week 49","Average_Delivery_Days":4},{"RouteID":"TSM","week_name":"2017 Week 49","Average_Delivery_Days":2},{"RouteID":"MK","week_name":"2017 Week 49","Average_Delivery_Days":1}],"filter_by":"Weekly"}

But I just can't get it right since based on my understanding, the route names should be the column names in order to make it right.

Wrong Graph:

Right Graph:

And my sample query:

SELECT [RouteID],
CAST(DATEPART(YEAR,[DeliveryDate]) as varchar) + ' Week ' + CAST(DATEPART(WEEK,[DeliveryDate]) AS varchar) AS week_name,
AVG(DATEDIFF(day, CONVERT(date, [UnloadDate]), CONVERT(date, [DeliveryDate]))) as Average_Delivery_Days
FROM [CARGODB].[dbo].[Cargo_Transactions]
WHERE [DeliveryDate] IS NOT NULL AND [DeliveryDate] != 0
AND CONVERT(date, [DeliveryDate]) BETWEEN '2016-01-01' AND GETDATE()
AND [UnloadDate] IS NOT NULL AND [UnloadDate] != 0 AND [DeliveryDate] > [UnloadDate]
AND [Deleted] = 0 and [StageID] = 'D' AND [RouteID] IN ('TSM', 'C', 'MK', 'CAV', 'PQU')
GROUP BY DATEPART(YEAR,[DeliveryDate]), DATEPART(WEEK,[DeliveryDate]), [RouteID]
ORDER BY DATEPART(YEAR,[DeliveryDate]), DATEPART(WEEK,[DeliveryDate]), Average_Delivery_Days desc

My Chart.js Code:

var date_created = [];
        var average_delivery_days = [];
        var route_name = [];
        var oss_new_customers = [];

        for(var i in data.data) {
            date_created.push(data.data[i]['week_name']);
            average_delivery_days.push(data.data[i]['Average_Delivery_Days']);
            route_name.push(data.data[i]['RouteID']);
        }

        var chartdata = {
            labels: date_created,
            datasets : [
                {
                    label: route_name,
                    backgroundColor: 'rgba(52, 152, 219,1.0)',
                    data: average_delivery_days,
                    legend: {
                        onClick: function(e){
                            hidden:true
                        }
                    }
                }
            ]
        };

        ctx = $("#delivery_performance_chart");
        delivery_performance_barGraph = new Chart(ctx, {
            type: 'bar',
            data: chartdata,
            options: {
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero:true
                        }
                    }]
                },
                tooltips: {
                    mode: 'index',
                    footerFontStyle: 'normal'
                },
                hover: {
                    mode: 'index',
                    intersect: true
                },
                scales: {
                    xAxes: [{
                        display: true,
                        scaleLabel: {
                            show: true
                        }
                    }],
                    yAxes: [{
                        display: true,
                        scaleLabel: {
                            show: true
                        }
                    }]
                },
                maintainAspectRatio: false,
                responsive:true
            }
        });

Your help is highly appreciated. Thanks!


问:
android.content.res.Resources$NotFoundException when string resource exists
I have a few strings which have been put in the android values/strings.xml file in my android project.

```<code><resources>
    <string name="level_reached_label">Level Reached: </string>
    <string name="endgame_textP1">You have scored </string>
    <string name="endgame_textP2"> points in </string>
    <string name="endgame_textP3"> seconds </string>
</resources>
</code>```

I call the strings with this line in one of my java classes

```<code>endLevelLabel.setText(R.string.level_reached_label + level);
endInfoLabel.setText(R.string.endgame_textP1 + score + R.string.endgame_textP2 + gameTime + R.string.endgame_textP3);
</code>```

The first line runs fine but the second line gives this error (the program works with the 2nd line commented out):

```<code> java.lang.RuntimeException: Unable to start activity ComponentInfo{com.web.mathtaketwo/com.web.mathtaketwo.EndGame}: android.content.res.Resources$NotFoundException: String resource ID #0x7d1500be
</code>```

What did i do wrong that stopped this string from working? Is it because i am trying to use multiple strings in 1 line combined with variables? Why does the other string load fine?

note: the two object that are being set are TextView's:

```<code>TextView endInfoLabel = (TextView)findViewById(R.id.endInfoLabel);
TextView endLevelLabel = (TextView)findViewById(R.id.endLevelLabel);
</code>```

答:
Okay so basically the problem is R.string.xxx returns only the ID of a string.

This results in many problems as i try to inserts ID's (integers) into my string.

Instead what i should have done was use the getString() function which returns the string at the id specified:

```<code>getString(R.string.xxxx)
</code>```

If i change my code using getString():

```<code>endLevelLabel.setText(getString(R.string.level_reached_label) + (level));
endInfoLabel.setText(getString(R.string.endgame_textP1) + score + getString(R.string.endgame_textP2) + gameTime + getString(R.string.endgame_textP3));
</code>```

Then it works correctly. For more details see these other topics which i looked at:

Reading value from string resource

String Resources

Get string from resource

Body:
I have a few strings which have been put in the android values/strings.xml file in my android project.

<resources>
    <string name="level_reached_label">Level Reached: </string>
    <string name="endgame_textP1">You have scored </string>
    <string name="endgame_textP2"> points in </string>
    <string name="endgame_textP3"> seconds </string>
</resources>

I call the strings with this line in one of my java classes

endLevelLabel.setText(R.string.level_reached_label + level);
endInfoLabel.setText(R.string.endgame_textP1 + score + R.string.endgame_textP2 + gameTime + R.string.endgame_textP3);

The first line runs fine but the second line gives this error (the program works with the 2nd line commented out):

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.web.mathtaketwo/com.web.mathtaketwo.EndGame}: android.content.res.Resources$NotFoundException: String resource ID #0x7d1500be

What did i do wrong that stopped this string from working? Is it because i am trying to use multiple strings in 1 line combined with variables? Why does the other string load fine?

note: the two object that are being set are TextView's:

TextView endInfoLabel = (TextView)findViewById(R.id.endInfoLabel);
TextView endLevelLabel = (TextView)findViewById(R.id.endLevelLabel);

Body:
Okay so basically the problem is R.string.xxx returns only the ID of a string.

This results in many problems as i try to inserts ID's (integers) into my string.

Instead what i should have done was use the getString() function which returns the string at the id specified:

getString(R.string.xxxx)

If i change my code using getString():

endLevelLabel.setText(getString(R.string.level_reached_label) + (level));
endInfoLabel.setText(getString(R.string.endgame_textP1) + score + getString(R.string.endgame_textP2) + gameTime + getString(R.string.endgame_textP3));

Then it works correctly. For more details see these other topics which i looked at:

Reading value from string resource

String Resources

Get string from resource


问:
django metismenu nav active on page change
I want to change the side menu highlighted field based on what page I am on. I've been working on this all day and cannot seem to solve the issue.

HTML:

```<code><!--- Start Side Navigation --->
<nav class="navbar-default navbar-static-side" role="navigation">
    <div class="sidebar-collapse">
        <ul class="nav metismenu" id="side-menu">
            <li class="nav-header">
                <div class="dropdown profile-element">
                 {% if sma.active == True %}
                      <span>
                          <img alt="image" class="img-circle" height="80" width="80" src="{{ sma.profile_picture_object.thumbnail_url }}" />
                      </span>
                 {% endif %}
                     <a data-toggle="dropdown" class="dropdown-toggle" href="#" aria-expanded="true">
                         <span class="clear">
                             <span class="text-muted text-xs block">
                                 <img src="small.png">
                             </span>
                         </span>
                      </a>
                  </div>
              </li>
              <li class="active">
                  <a href="{% url 'website:dashboard' %}">
                      <i class="fa fa-linode"></i>
                          <span class="nav-label">Dashboard</span>
                  </a>
              </li>
              <li class="">
                  <a href="#">
                      <i class="fa fa-user-o"></i>
                          <span class="nav-label">Accounts</span>
                              <span class="fa arrow"></span>
                  </a>
                  <ul class="nav nav-second-level">
                      <li class="">
                          <a href="{% url 'website:accounts_detail' sma.id %}">Current Account</a>
                      </li>
                      <li>
                          <a href="{% url 'website:accounts_edit' %}">Edit Account
                          </a>
                      </li>
                      <li>
                          <a href="{% url 'website:accounts_list'%}">Switch Account
                          </a>
                      </li>
                      <li>
                          <a href="{% url 'website:accounts_add' %}">Add Account
                          </a>
                      </li>
                  </ul>
              </li>
              <li>
                  <a href="#">
                      <i class="fa fa-sitemap"></i>
                          <span class="nav-label">Ambassadors</span>
                              <span class="fa arrow"></span>
                  </a>
                  <ul class="nav nav-second-level">
                      <li>
                          <a href="{% url 'website:ambassadors_list_active' %}">Search
                          </a>
                      </li>
                      <li>
                          <a href="{% url 'website:ambassadors_list_requested' %}">Requested
                          </a>
                      </li>
                      <li>
                          <a href="{% url 'website:ambassadors_list_authorized' %}">Authorized
                          </a>
                      </li>
                  </ul>
              </li>
          </ul>
      </div>
  </nav>
</code>```

JS:

```<code><script>
        $(document).ready(function () {
            var url = window.location;
            var element = $('ul.nav a').filter(function() {
                return this.href === url || url.href.indexOf(this.href) === 0;
            }).addClass('active');
            $(element.parents()).each(function() {
                if (this.className.indexOf('collapse') !== -1) {
                    $(this).addClass('in');
                }
            });
            element = element.parent().parent().parent();
            if (element.is('li')) {
                element.addClass('active');
            }
            $(function () {
                $('#side-menu').metisMenu();

            });
        });
    </script>
</code>```

This currently only works for the accounts page and only un-collapses the dropdown. I cannot seem to figure out how to highlight/active the correct li class. I also tried using django templates, however most of the urls are very similar to the accounts one where the url path is /accounts/userID/.

I would appreciate any help, I've been working on this for a few hours. I feel like I made progress with the last edits.

EDIT:

It also doesnt remove the active class from the dashboard li

答:
A pure django solution using django template tags is to take advantage of request.resolver_match.

So for each item that you want highlighted add this:

```<code>    <li class="{% if request.resolver_match.url_name == "website:accounts_detail" %}active{% endif %}" />
</code>```

Body:
I want to change the side menu highlighted field based on what page I am on. I've been working on this all day and cannot seem to solve the issue.

HTML:

                 {% if sma.active == True %}

                 {% endif %}

                          Dashboard

                          Accounts

                          Current Account

                          Edit Account

                          Switch Account

                          Add Account

                          Ambassadors

                          Search

                          Requested

                          Authorized

JS:

This currently only works for the accounts page and only un-collapses the dropdown. I cannot seem to figure out how to highlight/active the correct li class. I also tried using django templates, however most of the urls are very similar to the accounts one where the url path is /accounts/userID/.

I would appreciate any help, I've been working on this for a few hours. I feel like I made progress with the last edits.

EDIT:

It also doesnt remove the active class from the dashboard li

Body:
A pure django solution using django template tags is to take advantage of request.resolver_match.

So for each item that you want highlighted add this:

    <li class="{% if request.resolver_match.url_name == "website:accounts_detail" %}active{% endif %}" />


问:
Position fixed div with relative to the parent container
I want to add a div in right sidebar which is fixed and relative to the parent container just like this in this website see the right sidebar this is exactly what I want for my website

I tried many things but not got any result here is my code

```<code><div id="parent_div">
 <div id="fixed_div">
  Some Content here.....
 </div>
</div>

parent_div
{
 float:right;
 width:300px;
 margin-top:50px;
 margin-right:5px;
 position:relative;
 border:1px solid red;
}

fixed_div
{
 position:fixed;
 width:300px;
 background-color:#084B8A;
 padding:10px;
 box-sizing:border-box;
}
</code>```

How can I do this in css which is cross browser and if it is not possible in css how can I do this in jquery or javascript

答:
Make use of jquery scrollTop.Have a look at the below code.

$(window).scroll(function(){
    $("#theFixed").css("top",Math.max(0,250-$(this).scrollTop()));
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<div id="theFixed" style="position:fixed;top:250px;right:30px;background-color:red">Fixed Div</div>

CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR></code>```

ContentLicense: CC BY-SA 4.0

Body:
I want to add a div in right sidebar which is fixed and relative to the parent container just like this in this website see the right sidebar this is exactly what I want for my website

I tried many things but not got any result here is my code

  Some Content here.....

parent_div
{
 float:right;
 width:300px;
 margin-top:50px;
 margin-right:5px;
 position:relative;
 border:1px solid red;
}

fixed_div
{
 position:fixed;
 width:300px;
 background-color:#084B8A;
 padding:10px;
 box-sizing:border-box;
}

How can I do this in css which is cross browser and if it is not possible in css how can I do this in jquery or javascript

Body:
Make use of jquery scrollTop.Have a look at the below code.

$(window).scroll(function(){
    $("#theFixed").css("top",Math.max(0,250-$(this).scrollTop()));
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<div id="theFixed" style="position:fixed;top:250px;right:30px;background-color:red">Fixed Div</div>

CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>CONTENT <BR>


问:
Data Modeling: Supertype / Subtype
Looking to figure out the proper way to model the below requirements.

There are 3 types of “parties” to be concerned with, a Fan, a Band, and a BandMember.

That BandMember will always be associated with a Band and can also be a Fan of any band.

There are common attributes between a Fan, a Band, and a BandMember, but each of these 3 will also have their own unique attributes.

A Fan can be a fan of of any Band or none at all

This is a small part of a bigger thought but it is creating confusion in expanding the model.  I believe it would have to be diagram 2 or some other option since I don't see how a BandMember can be associated with a Band in the first model.

I appreciate any input.

答:
Caveat

First a couple of caveats for understanding the limitations.  All the data being used or stored needs to be considered/modelled together.  Eg. you have found that out anyway in your "creating confusion in expanding the model". From my side, not knowing how the Parties (subtypes) are related to other entities, limits me from provided a totally correct answer (that will not change).

Since you are providing the data in two tranches, therefore the answer will be in two tranches, and the second tranche will require changes to the first model.  Not a complaint, just advising you beforehand, as that could be avoided if I saw all the data up front.

It is really great that you appreciate the need for (a) modelling the data and (b) going through the science (documented for over 30 years) of Conceptual, Logical, then physical.  That is exactly what I do. You cannot imagine the time and effort that is saved by the formal process.

However, that does not come across in my answers at SO, because it is a "question and answer" site, I have to answer at the level of the questioner. (I answer questions more fully than others, and even that, causes negative commentary !).  Be assured that I go through the formal sequence.

It must be mentioned that Relation Modelling is the work of giants in the industry, Dr E F Codd and R Brown in the 1980's.  The Methodology is based on their work.  IDEF1X became a NIST Standard in 1993. When I answer Data Modelling questions, I am not supplying some personal method that I wrote a book about, I stand on the shoulders of giants.

I adhere to the Relational Model by Dr E F Codd.

I reject the work of Date; Darwen; Fagin; etc, because it contradicts the Relational Model, it is anti-Relational.

ERD (P Chen) is pre-relational, pre-IDEF1X, and primitive in comparison.  It has not concept of the Identifier, it cannot handle a Relational Key.  It is staggering that ERD is still being taught as "relational", and IDEF1X is suppressed.  For 30 years.

Data Modelling

Yes, a Supertype-Subtype structure is correct here.  Unfortunately it is not common and therefore not commonly understood.

Subtypes existed long before the Relational Model, and continues to exist.  IDEF1X, the only Standard for Relational Data Modelling, has specific symbols for it.  ERD has nothing.

Separately, even where Subtypes are implemented, they are implemented in very limited fashion.  Subtypes have the effect of changing the Role of the Supertype. The correct implementation of that is very rare indeed, I have not seen this anywhere (except of course my own database implementations for customers, and a few high-end suppliers).

Point is, that may look "complex" but it isn't, it is actually very simple.

This is where Ken Downs and Chris Behrens confuse modelled simplicity (highly extensible) with unmodelled implementation (incorrect and un-extensible), due to the simplistic approach advised by dwarves such as Martin Fowler.  No offence, I understand that people are attached to, and will defend, what they know, however limited as that may be.

notice that each Subtype is also a perfectly valid Entity (Table in the Physical, when we get to that stage) in its own right, and can stand on its own.

for the lower levels or transaction or function tables, which have Relations to these Subtypes, the trick is to use the correct Subtype (Role).  The common mistake is they use Party, and then the meaning of the Subtype or Role, and the correct Referential Integrity is lost.

separately all the RoleNames are derived from Party, but that is not a valid reason to useParty instead of the correct Role.

Here you understand the data really well, but (no one has taught you this and) you have confused Roles and Subtypes.

BandMember and Fan are not Parties.  They are Persons, first (and Person is a Party, second)

In order to provide clarity re those points, at this Conceptual level, we need to work with Entities and Identifiers (not Attributes), rather than just Entities.  Therefore I have provided that as well.

It appears you have ERwin (the best!); it allows you to view the single model at that level very conveniently.  Do implement the Identifiers in the Entities, even at this abstract level.

Obstacle

I point these out before presenting the model, because you appear to be seriously interested in learning IDEF1X, the Standard methodolgy for modelling Relational Databases, with a view to easing your models in the future. SO or any website, is not a good medium for formal interactive education, but we will give it our best shot.

In model (1), Band cannot be Independent (square corners): since it is identified as being Dependent on Party; it is a Subtype of Party; and it has the same Identifier.

The missing Cardinality is critical.  Putting it in will actually assist in resolving the model.  I am not fussed re IDEF1X (circles) vs IEEE (crows feet), but I always put them in as I go, and keep changing them as the model progresses.

your model does not show that a Band is made up of one-to-many Members. Et cetera.

.

While programming can progress incrementally (once the definition is stable)), modelling does not. Eg. you can't model the Entities but not the Relations; the Relations but not the Cardinality.  That is why they are different sciences, programmers do not make good modellers, and vice versa.

.

At this stage the Rules are also very important.  Modelling is, in fact, modelling the Rules.  Therefore correcting or modulating the Rules is part of the Modelling process.

A Fan can be a fan of of any Band or none at all is not reasonable. If a Person is none at all then they are a member of the general public, and they have no Relation to any Band.  An ordinary Person.

A Fan has a Relation to at least one Band.  In fact, having a Relation to a Band is what takes a Person out of that realm and causes storage of Fan details or specific fan-of-band details.

If there are is such an Entity as Fan with no Band (ie. you are storing details of that, separate to Fan as per my model), please advise, and I will change the model (paper is cheap!).

Verb Phrases are also important at this stage; no less than my point re Rules and Cardinality above, it is a part of the modelling process, and it needs change/modulation as the model progresses.  You will not believe how important it is to gett the Verb Phrases right. Putting them in may well have assisted you in clarifying Subtypes vs Roles. Here is a definition that every Data Modeller knows by heart.

The Entities are the Nouns in the model

The Relations are the Verbs, the actions that take place between the Nouns

The Verb Phrases define those actions (that's why they are accurately called Verb Phrases, it is not a funny name).

As described in the IDEF1X Notation document, for Associative tables, read the Verb Phrase "through" them, to the parent on the other side of the association.

A Person makes one-to-many Bands, and is thus a Member

A Band is made up of one-to-many People, who are Members

A Person patronises a Band, which makes them a Fan (not merely a Person who has a row in the Fan table)

A Band depends on People, who are Fans

Coming up with the shortest, most meaningful, Verb Phrase; not using simplistic words ("comprises" is to be avoided"), is a challenge for Modellers. Feel free to ameliorate the Verb phrases I supplied.

Here is your Party Data Model at the Entity and Key levels in IDEF1X.

Readers who are unfamiliar with the Standard for Modelling Relational Databases may find my IDEF1X Notation useful.

Note

All I have done is resolve the Subtypes; Roles; the Cardinality of the Relations, as identified above.

The relevance of the Subtypes vs Roles will be more clear to you when you evaluate your second tranche or your transaction Entities (as you have stated, here we have only Identifying Entities).

Identifiers.  This is worth spelling out, not only for the purpose of clarifying the model, also because it is a good example of IDEF1X Identifiers being used, and the power they deploy.  You have already indicated in your model that you understand that (solid lines), I am merely giving it the full treatment.

Person and Band are Subtypes of Party.  They are also Roles of Party. Therefore we use PersonId and BandId from that point downward, not PartyId (even though it is PartyId).

When a Person plays the Role of Member, we use MemberId (which is PersonId, which is PartyId).

When a Person plays the Role of Fan, we use FanId (which is PersonId, which is PartyId).

Let's say you were listing the Fans of a Band, your query is centred on Fan.  If you had those Id Surrogate Keys on every table, you would be forced to join Person, then join Party. But with the Relational Identifiers you have, you can go directly to Party:

SELECT  ...,
        Name  -- Party.Name
        ...
    FROM Party
    JOIN Fan
        ON PartyId = FanId
```

and skip the Band table in-between.  Yes, the truth is, Normalised Relational Database require fewer joins, less resources (processing, cache, disk I/O), and that is one reason why they perform so much better.  The myth has no scientific basis.

Please evaluate and ask specific questions.

Update

For a generic treatment of Subtypes, and implementation details for genuine SQL platforms, refer to my Subtype Document.

ContentLicense: CC BY-SA 2.5

Title: Data Modeling: Supertype / Subtype

Body:
Caveat

First a couple of caveats for understanding the limitations.  All the data being used or stored needs to be considered/modelled together.  Eg. you have found that out anyway in your "creating confusion in expanding the model". From my side, not knowing how the Parties (subtypes) are related to other entities, limits me from provided a totally correct answer (that will not change).

Since you are providing the data in two tranches, therefore the answer will be in two tranches, and the second tranche will require changes to the first model.  Not a complaint, just advising you beforehand, as that could be avoided if I saw all the data up front.

It is really great that you appreciate the need for (a) modelling the data and (b) going through the science (documented for over 30 years) of Conceptual, Logical, then physical.  That is exactly what I do. You cannot imagine the time and effort that is saved by the formal process.

However, that does not come across in my answers at SO, because it is a "question and answer" site, I have to answer at the level of the questioner. (I answer questions more fully than others, and even that, causes negative commentary !).  Be assured that I go through the formal sequence.

It must be mentioned that Relation Modelling is the work of giants in the industry, Dr E F Codd and R Brown in the 1980's.  The Methodology is based on their work.  IDEF1X became a NIST Standard in 1993. When I answer Data Modelling questions, I am not supplying some personal method that I wrote a book about, I stand on the shoulders of giants.

I adhere to the Relational Model by Dr E F Codd.

I reject the work of Date; Darwen; Fagin; etc, because it contradicts the Relational Model, it is anti-Relational.

ERD (P Chen) is pre-relational, pre-IDEF1X, and primitive in comparison.  It has not concept of the Identifier, it cannot handle a Relational Key.  It is staggering that ERD is still being taught as "relational", and IDEF1X is suppressed.  For 30 years.

Data Modelling

Yes, a Supertype-Subtype structure is correct here.  Unfortunately it is not common and therefore not commonly understood.

Subtypes existed long before the Relational Model, and continues to exist.  IDEF1X, the only Standard for Relational Data Modelling, has specific symbols for it.  ERD has nothing.

Separately, even where Subtypes are implemented, they are implemented in very limited fashion.  Subtypes have the effect of changing the Role of the Supertype. The correct implementation of that is very rare indeed, I have not seen this anywhere (except of course my own database implementations for customers, and a few high-end suppliers).

Point is, that may look "complex" but it isn't, it is actually very simple.

This is where Ken Downs and Chris Behrens confuse modelled simplicity (highly extensible) with unmodelled implementation (incorrect and un-extensible), due to the simplistic approach advised by dwarves such as Martin Fowler.  No offence, I understand that people are attached to, and will defend, what they know, however limited as that may be.

notice that each Subtype is also a perfectly valid Entity (Table in the Physical, when we get to that stage) in its own right, and can stand on its own.

for the lower levels or transaction or function tables, which have Relations to these Subtypes, the trick is to use the correct Subtype (Role).  The common mistake is they use Party, and then the meaning of the Subtype or Role, and the correct Referential Integrity is lost.

separately all the RoleNames are derived from Party, but that is not a valid reason to useParty instead of the correct Role.

Here you understand the data really well, but (no one has taught you this and) you have confused Roles and Subtypes.

BandMember and Fan are not Parties.  They are Persons, first (and Person is a Party, second)

In order to provide clarity re those points, at this Conceptual level, we need to work with Entities and Identifiers (not Attributes), rather than just Entities.  Therefore I have provided that as well.

It appears you have ERwin (the best!); it allows you to view the single model at that level very conveniently.  Do implement the Identifiers in the Entities, even at this abstract level.

Obstacle

I point these out before presenting the model, because you appear to be seriously interested in learning IDEF1X, the Standard methodolgy for modelling Relational Databases, with a view to easing your models in the future. SO or any website, is not a good medium for formal interactive education, but we will give it our best shot.

In model (1), Band cannot be Independent (square corners): since it is identified as being Dependent on Party; it is a Subtype of Party; and it has the same Identifier.

The missing Cardinality is critical.  Putting it in will actually assist in resolving the model.  I am not fussed re IDEF1X (circles) vs IEEE (crows feet), but I always put them in as I go, and keep changing them as the model progresses.

your model does not show that a Band is made up of one-to-many Members. Et cetera.

.

While programming can progress incrementally (once the definition is stable)), modelling does not. Eg. you can't model the Entities but not the Relations; the Relations but not the Cardinality.  That is why they are different sciences, programmers do not make good modellers, and vice versa.

.

At this stage the Rules are also very important.  Modelling is, in fact, modelling the Rules.  Therefore correcting or modulating the Rules is part of the Modelling process.

A Fan can be a fan of of any Band or none at all is not reasonable. If a Person is none at all then they are a member of the general public, and they have no Relation to any Band.  An ordinary Person.

A Fan has a Relation to at least one Band.  In fact, having a Relation to a Band is what takes a Person out of that realm and causes storage of Fan details or specific fan-of-band details.

If there are is such an Entity as Fan with no Band (ie. you are storing details of that, separate to Fan as per my model), please advise, and I will change the model (paper is cheap!).

Verb Phrases are also important at this stage; no less than my point re Rules and Cardinality above, it is a part of the modelling process, and it needs change/modulation as the model progresses.  You will not believe how important it is to gett the Verb Phrases right. Putting them in may well have assisted you in clarifying Subtypes vs Roles. Here is a definition that every Data Modeller knows by heart.

The Entities are the Nouns in the model

The Relations are the Verbs, the actions that take place between the Nouns

The Verb Phrases define those actions (that's why they are accurately called Verb Phrases, it is not a funny name).

As described in the IDEF1X Notation document, for Associative tables, read the Verb Phrase "through" them, to the parent on the other side of the association.

A Person makes one-to-many Bands, and is thus a Member

A Band is made up of one-to-many People, who are Members

A Person patronises a Band, which makes them a Fan (not merely a Person who has a row in the Fan table)

A Band depends on People, who are Fans

Coming up with the shortest, most meaningful, Verb Phrase; not using simplistic words ("comprises" is to be avoided"), is a challenge for Modellers. Feel free to ameliorate the Verb phrases I supplied.

Here is your Party Data Model at the Entity and Key levels in IDEF1X.

Readers who are unfamiliar with the Standard for Modelling Relational Databases may find my IDEF1X Notation useful.

Note

All I have done is resolve the Subtypes; Roles; the Cardinality of the Relations, as identified above.

The relevance of the Subtypes vs Roles will be more clear to you when you evaluate your second tranche or your transaction Entities (as you have stated, here we have only Identifying Entities).

Identifiers.  This is worth spelling out, not only for the purpose of clarifying the model, also because it is a good example of IDEF1X Identifiers being used, and the power they deploy.  You have already indicated in your model that you understand that (solid lines), I am merely giving it the full treatment.

Person and Band are Subtypes of Party.  They are also Roles of Party. Therefore we use PersonId and BandId from that point downward, not PartyId (even though it is PartyId).

When a Person plays the Role of Member, we use MemberId (which is PersonId, which is PartyId).

When a Person plays the Role of Fan, we use FanId (which is PersonId, which is PartyId).

Let's say you were listing the Fans of a Band, your query is centred on Fan.  If you had those Id Surrogate Keys on every table, you would be forced to join Person, then join Party. But with the Relational Identifiers you have, you can go directly to Party:

SELECT  ...,
        Name  -- Party.Name
        ...
    FROM Party
    JOIN Fan
        ON PartyId = FanId

and skip the Band table in-between.  Yes, the truth is, Normalised Relational Database require fewer joins, less resources (processing, cache, disk I/O), and that is one reason why they perform so much better.  The myth has no scientific basis.

Please evaluate and ask specific questions.

Update

For a generic treatment of Subtypes, and implementation details for genuine SQL platforms, refer to my Subtype Document.


问:
scp to remote server asking for passphrase despite adding public key to authorized keys
There are several similar questions on Stack Overflow itself, but none worked.

I have a server called remote and I am trying to copy some file from my local machine. Both are Ubuntu machines : local is Ubuntu 16 and remote is Ubuntu 14.

I have added my local public key to the remote server at ~/.ssh/authorized_keys. Before adding the keys I was prompted for the password to the remote machine, but now I am being prompted for the key passphrase.

There are my permissions on the remote machine :

```<code>drwx------ 2 ops ops 4096 Dec  5 07:38 .
drwxr-xr-x 5 ops ops 4096 Dec  6 02:06 ..
-rwx------ 1 ops ops  743 Dec  5 03:56 authorized_keys
-rw------- 1 ops ops 3326 Dec  5 04:04 id_rsa
-rw-r--r-- 1 ops ops  751 Dec  5 04:04 id_rsa.pub
-rwx------ 1 ops ops  444 Dec  5 06:55 known_hosts
</code>```

This is my verbose ssh log :

```<code>OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to gateway [172.16.24.1] port 22.
debug1: Connection established.
debug1: identity file /home/ops/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to gateway:22 as 'ops'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:TgaQlbi1L+JBQBbqhJZHIpDnXtJGZtw5y3r2fj7qFAM
debug1: Host 'gateway' is known and matches the ECDSA host key.
debug1: Found key in /home/ops/.ssh/known_hosts:2
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/ops/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
Enter passphrase for key '/home/ops/.ssh/id_rsa':
</code>```

Can someone please help on this.

答: Pretty sure your key is password protected. It is prompting you to unlock that not log into the server.</p>

Body:
There are several similar questions on Stack Overflow itself, but none worked.

I have a server called remote and I am trying to copy some file from my local machine. Both are Ubuntu machines : local is Ubuntu 16 and remote is Ubuntu 14.

I have added my local public key to the remote server at ~/.ssh/authorized_keys. Before adding the keys I was prompted for the password to the remote machine, but now I am being prompted for the key passphrase.

There are my permissions on the remote machine :

drwx------ 2 ops ops 4096 Dec  5 07:38 .
drwxr-xr-x 5 ops ops 4096 Dec  6 02:06 ..
-rwx------ 1 ops ops  743 Dec  5 03:56 authorized_keys
-rw------- 1 ops ops 3326 Dec  5 04:04 id_rsa
-rw-r--r-- 1 ops ops  751 Dec  5 04:04 id_rsa.pub
-rwx------ 1 ops ops  444 Dec  5 06:55 known_hosts

This is my verbose ssh log :

OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to gateway [172.16.24.1] port 22.
debug1: Connection established.
debug1: identity file /home/ops/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/ops/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to gateway:22 as 'ops'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:TgaQlbi1L+JBQBbqhJZHIpDnXtJGZtw5y3r2fj7qFAM
debug1: Host 'gateway' is known and matches the ECDSA host key.
debug1: Found key in /home/ops/.ssh/known_hosts:2
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/ops/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
Enter passphrase for key '/home/ops/.ssh/id_rsa':

Can someone please help on this.