问:
DRF Cursor Pagination example
I'm trying to setup CursorPagination with DRF for a list of transaction records (ordered by creation date).
I can't figure out how to do an initial request because I don't know the cursor yet at that stage. Surprisingly, I can't find an example of this.

Also, is there a way to set the page size per request with CursorPagination, the PageNumberPagination have page_size_query_param and max_page_size and they aren't there for CursorPagination.

Here's what I have so far:

```<code>class RecordPagination(pagination.CursorPagination):
    page_size = 10

class RecordsOverview(generics.ListAPIView):
    serializer_class = RecordSerializer
    logging_methods = ['GET']

    queryset = Record.objects.all()
    pagination_class = RecordPagination

    # Note: this is my way to dynamically set the page size,
    # it is totally hacky, so I'm open to suggestions
    # is_number method is left out for brevity
    def get(self, request, *args, **kwargs):
        page_size = request.GET.get('page_size', '')

        if self.is_number(page_size) and int(page_size) > 0:
            self.paginator.page_size = int(page_size)

        return self.list(request, *args, **kwargs)
</code>```

Then in my test I do a GET request:

```<code>response = self.client.get(GET_RECORDS_URL, data={'page_size': 2})
</code>```

I get back a 'next' url that looks something like this:

```<code>http://testserver/api/v1/records/?cursor=cj0xJnA9MjAxNy0wOS0yMCsxNCUzQTM0JTNBNDkuNjUxMDU4JTJCMDAlM0EwMA%3D%3D&page_size=2
</code>```

If I do get(next_url) I will get the next records OK, and this time I don't have to pass data={'page_size': 2}.

Please, let me know if I can do all of this in a cleaner and more consistent way.

答:
This is how I use CursorPagination without any complications:</p>
```<code>from rest_framework.pagination import CursorPagination

class CursorSetPagination(CursorPagination):
    page_size = 5
    page_size_query_param = 'page_size'
    ordering = '-timestamp' # '-created' is default

class MyListAPIView(generics.ListAPIView):
    queryset = MyObject.objects.all()
    serializer_class = MySerializer
    pagination_class = CursorSetPagination
</code>```

ContentLicense: CC BY-SA 4.0

Title: DRF Cursor Pagination example

Body:
I'm trying to setup CursorPagination with DRF for a list of transaction records (ordered by creation date).
I can't figure out how to do an initial request because I don't know the cursor yet at that stage. Surprisingly, I can't find an example of this.

Also, is there a way to set the page size per request with CursorPagination, the PageNumberPagination have page_size_query_param and max_page_size and they aren't there for CursorPagination.

Here's what I have so far:

class RecordPagination(pagination.CursorPagination):
    page_size = 10

class RecordsOverview(generics.ListAPIView):
    serializer_class = RecordSerializer
    logging_methods = ['GET']

    queryset = Record.objects.all()
    pagination_class = RecordPagination

    # Note: this is my way to dynamically set the page size,
    # it is totally hacky, so I'm open to suggestions
    # is_number method is left out for brevity
    def get(self, request, *args, **kwargs):
        page_size = request.GET.get('page_size', '')

        if self.is_number(page_size) and int(page_size) > 0:
            self.paginator.page_size = int(page_size)

        return self.list(request, *args, **kwargs)

Then in my test I do a GET request:

response = self.client.get(GET_RECORDS_URL, data={'page_size': 2})

I get back a 'next' url that looks something like this:

http://testserver/api/v1/records/?cursor=cj0xJnA9MjAxNy0wOS0yMCsxNCUzQTM0JTNBNDkuNjUxMDU4JTJCMDAlM0EwMA%3D%3D&page_size=2

If I do get(next_url) I will get the next records OK, and this time I don't have to pass data={'page_size': 2}.

Please, let me know if I can do all of this in a cleaner and more consistent way.

Body:
This is how I use CursorPagination without any complications:

from rest_framework.pagination import CursorPagination

class CursorSetPagination(CursorPagination):
    page_size = 5
    page_size_query_param = 'page_size'
    ordering = '-timestamp' # '-created' is default

class MyListAPIView(generics.ListAPIView):
    queryset = MyObject.objects.all()
    serializer_class = MySerializer
    pagination_class = CursorSetPagination


来源: stackexchange

问:
How to update template on @click

Code

I have the following code. I want to update the results-box with a random selected choice. How would I update the template on a @click event.

```<code><template>
  <div class="container">
    <button @click="getDecision()" class="ui primary button">Discover</button>
    <p id="results-box"></p>
  </div>
</template>

<script>
  export default {
    name: "SlapButton",
    data() {
      return {

      }
    },
    methods: {
      getDecision: function () {
        var decisions = [
          "choice 1",
          "choice 2",
          "choice 3",
          "choice 4",
          "choice 5",
          "choice 6"
        ]
        var randNum = Math.floor((Math.random() * decisions.length) + 0);
        var randChoice = decisions[randNum];
      }
    }
  }

</script>
</code>```

Question

When the user clicks on the button getDecision() is called and it selects a random choice from the the decisions array. How do I display this random choice randChoice within the p tag #results-box.

答:
try the following code and please elaborate if this doesn't work:</p>

```<code><template>
  <div class="container">
    <button @click="getDecision" class="ui primary button">Discover</button>
    <p id="results-box">
      {{choice}}
    </p>
  </div>
</template>

<script>
  export default {
    name: "SlapButton",
    data() {
      return {
        choice: '',
        decisions = [
                  "choice 1",
                  "choice 2",
                  "choice 3",
                  "choice 4",
                  "choice 5",
                  "choice 6"
                ]
      }
    },
    methods: {
      getDecision() {
        var randNum = Math.floor((Math.random() * this.decisions.length) + 0);
        this.choice = this.decisions[randNum];
      }
    }
  }

</script>
</code>```

ContentLicense: CC BY-SA 3.0

Title: How to update template on @click

Body:
Code

I have the following code. I want to update the results-box with a random selected choice. How would I update the template on a @click event.

<template>

    <button @click="getDecision()" class="ui primary button">Discover</button>

</template>

Question

When the user clicks on the button getDecision() is called and it selects a random choice from the the decisions array. How do I display this random choice randChoice within the p tag #results-box.

Body:
try the following code and please elaborate if this doesn't work:

<template>
  <div class="container">
    <button @click="getDecision" class="ui primary button">Discover</button>
    <p id="results-box">
      {{choice}}
    </p>
  </div>
</template>

<script>
  export default {
    name: "SlapButton",
    data() {
      return {
        choice: '',
        decisions = [
                  "choice 1",
                  "choice 2",
                  "choice 3",
                  "choice 4",
                  "choice 5",
                  "choice 6"
                ]
      }
    },
    methods: {
      getDecision() {
        var randNum = Math.floor((Math.random() * this.decisions.length) + 0);
        this.choice = this.decisions[randNum];
      }
    }
  }

</script>


问:
Unable to start SonarQube after migration from 6.0 -> 6.7 LTS
I'm trying to upgrade my SonarQube instance from a SonarQube 6.0 installation to  SonarQube 6.7.

When I start SonarQube, its failing with the following exception:

```<code>2017.11.21 05:22:43 ERROR web[][o.s.s.p.Platform] Background initialization failed. Stopping SonarQube
java.lang.IllegalArgumentException: There is already a quality profile with name 'Sonar way' for language 'java'
    at org.sonar.api.internal.google.common.base.Preconditions.checkArgument(Preconditions.java:145)
    at org.sonar.api.server.profile.BuiltInQualityProfilesDefinition$Context.registerProfile(BuiltInQualityProfilesDefinition.java:78)
    at org.sonar.api.server.profile.BuiltInQualityProfilesDefinition$Context.access$300(BuiltInQualityProfilesDefinition.java:62)
    at org.sonar.api.server.profile.BuiltInQualityProfilesDefinition$NewBuiltInQualityProfileImpl.done(BuiltInQualityProfilesDefinition.java:170)
    at org.sonar.server.qualityprofile.BuiltInQProfileDefinitionsBridge.define(BuiltInQProfileDefinitionsBridge.java:88)
    at org.sonar.server.qualityprofile.BuiltInQProfileDefinitionsBridge.define(BuiltInQProfileDefinitionsBridge.java:67)
    at org.sonar.server.qualityprofile.BuiltInQProfileRepositoryImpl.initialize(BuiltInQProfileRepositoryImpl.java:68)
    at org.sonar.server.qualityprofile.BuiltInQProfileLoader.start(BuiltInQProfileLoader.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
    at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(ReflectionLifecycleStrategy.java:89)
    at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
    at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
    at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
    at org.picocontainer.behaviors.Stored.start(Stored.java:110)
    at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
    at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
    at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:134)
    at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
    at org.sonar.server.platform.platformlevel.PlatformLevelStartup.access$001(PlatformLevelStartup.java:45)
    at org.sonar.server.platform.platformlevel.PlatformLevelStartup$1.doPrivileged(PlatformLevelStartup.java:83)
    at org.sonar.server.user.DoPrivileged.execute(DoPrivileged.java:45)
    at org.sonar.server.platform.platformlevel.PlatformLevelStartup.start(PlatformLevelStartup.java:80)
    at org.sonar.server.platform.Platform.executeStartupTasks(Platform.java:196)
    at org.sonar.server.platform.Platform.access$400(Platform.java:46)
    at org.sonar.server.platform.Platform$1.lambda$doRun$1(Platform.java:121)
    at org.sonar.server.platform.Platform$AutoStarterRunnable.runIfNotAborted(Platform.java:371)
    at org.sonar.server.platform.Platform$1.doRun(Platform.java:121)
    at org.sonar.server.platform.Platform$AutoStarterRunnable.run(Platform.java:355)
    at java.lang.Thread.run(Thread.java:745)
2017.11.21 05:22:43 INFO  web[][o.s.p.StopWatcher] Stopping process
</code>```

Is there a way to fix this problem?

I have not heavily edited the quality profile, so I'm comfortable with reverting that back to defaults.

答:
As mentioned in the comments, it might be a problem of an outdated plugin. Here is what I did to solve the issue:

Remove the sonar-java plugin file from the extensions/plugins/ folder. (Also remove any plugins depending on java, if you see error messages for this in ce.log .)

If you are behind a proxy set up proxy settings for Marketplace in conf/sonar.properties . Note, that Marketplace does not claims for connection errors (at least in current version) just does not shows up available plugins. (But does log connection errors to web.log .)

Stop, and start SonarQube.

Login as Admin, and install the latest version of SonarJava plugin from Marketplace.

Body:
I'm trying to upgrade my SonarQube instance from a SonarQube 6.0 installation to  SonarQube 6.7.

When I start SonarQube, its failing with the following exception:

2017.11.21 05:22:43 ERROR web[][o.s.s.p.Platform] Background initialization failed. Stopping SonarQube
java.lang.IllegalArgumentException: There is already a quality profile with name 'Sonar way' for language 'java'
    at org.sonar.api.internal.google.common.base.Preconditions.checkArgument(Preconditions.java:145)
    at org.sonar.api.server.profile.BuiltInQualityProfilesDefinition$Context.registerProfile(BuiltInQualityProfilesDefinition.java:78)
    at org.sonar.api.server.profile.BuiltInQualityProfilesDefinition$Context.access$300(BuiltInQualityProfilesDefinition.java:62)
    at org.sonar.api.server.profile.BuiltInQualityProfilesDefinition$NewBuiltInQualityProfileImpl.done(BuiltInQualityProfilesDefinition.java:170)
    at org.sonar.server.qualityprofile.BuiltInQProfileDefinitionsBridge.define(BuiltInQProfileDefinitionsBridge.java:88)
    at org.sonar.server.qualityprofile.BuiltInQProfileDefinitionsBridge.define(BuiltInQProfileDefinitionsBridge.java:67)
    at org.sonar.server.qualityprofile.BuiltInQProfileRepositoryImpl.initialize(BuiltInQProfileRepositoryImpl.java:68)
    at org.sonar.server.qualityprofile.BuiltInQProfileLoader.start(BuiltInQProfileLoader.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
    at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.start(ReflectionLifecycleStrategy.java:89)
    at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
    at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
    at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
    at org.picocontainer.behaviors.Stored.start(Stored.java:110)
    at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
    at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
    at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
    at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:134)
    at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
    at org.sonar.server.platform.platformlevel.PlatformLevelStartup.access$001(PlatformLevelStartup.java:45)
    at org.sonar.server.platform.platformlevel.PlatformLevelStartup$1.doPrivileged(PlatformLevelStartup.java:83)
    at org.sonar.server.user.DoPrivileged.execute(DoPrivileged.java:45)
    at org.sonar.server.platform.platformlevel.PlatformLevelStartup.start(PlatformLevelStartup.java:80)
    at org.sonar.server.platform.Platform.executeStartupTasks(Platform.java:196)
    at org.sonar.server.platform.Platform.access$400(Platform.java:46)
    at org.sonar.server.platform.Platform$1.lambda$doRun$1(Platform.java:121)
    at org.sonar.server.platform.Platform$AutoStarterRunnable.runIfNotAborted(Platform.java:371)
    at org.sonar.server.platform.Platform$1.doRun(Platform.java:121)
    at org.sonar.server.platform.Platform$AutoStarterRunnable.run(Platform.java:355)
    at java.lang.Thread.run(Thread.java:745)
2017.11.21 05:22:43 INFO  web[][o.s.p.StopWatcher] Stopping process

Is there a way to fix this problem?

I have not heavily edited the quality profile, so I'm comfortable with reverting that back to defaults.


问:
reading from a file(whose contents are copied from another file) in java

i am reading from a text file(a file in which i wrote some sentences) and printing its contents everything was going well until i copied the same sentences from a PDF file, then nothing is printed into the console ,giving me build successful.

this is my code:

```<code>        File f=new File("input.txt");
        Scanner sc=new Scanner(f);
        while (sc.hasNext())
        {
            String line=sc.nextLine();
            int i=0;
            while ( i< line.length())
            {
                char c=line.charAt(i);
                System.out.println(c);
                i++;
            }
        }
        sc.close();
</code>```

the contents of the text file (whether when i write the sentences by myself or copy it from the PDF):

```<code>{sample program in TINY language- computes factorial}
read x;{input an integer}
if 0<x then {don’t compute if x<=0}
fact:=1;
repeat
fact:=fact*x;
x:=x-1
</code>```

what am i doing wrong and what to do if i wanted to copy sentences from a PDF file into the text file i am reading from

答:
If you want extract text or other information from pdf file use Oracle's library PDFBox.

PDFBox is the best library for this purpose, it's comprehensive and really quite easy to use if you're just doing basic text extraction.

Body:
i am reading from a text file(a file in which i wrote some sentences) and printing its contents everything was going well until i copied the same sentences from a PDF file, then nothing is printed into the console ,giving me build successful.

this is my code:

        File f=new File("input.txt");
        Scanner sc=new Scanner(f);
        while (sc.hasNext())
        {
            String line=sc.nextLine();
            int i=0;
            while ( i< line.length())
            {
                char c=line.charAt(i);
                System.out.println(c);
                i++;
            }
        }
        sc.close();

the contents of the text file (whether when i write the sentences by myself or copy it from the PDF):

{sample program in TINY language- computes factorial}
read x;{input an integer}
if 0<x then {don’t compute if x<=0}
fact:=1;
repeat
fact:=fact*x;
x:=x-1

what am i doing wrong and what to do if i wanted to copy sentences from a PDF file into the text file i am reading from


问:
Primefaces: How can I create a popup list?
I want to make a button that when is pressed will show a popup with a list of objects, from which I can select one to see it's details. How can I do this?</p>

答:
It's a standard Swing component - called JPopUpMenu

Use the ActionListener interface on the JButton (I assume you are using Swing) to pop it up.

Good wishes, - M.S.

Oops, Sorry, I thought it was a Java question.... didnt read the jsf tag. Please ignore.

ContentLicense: CC BY-SA 2.5


问:
Search array of dissimilar hashes
I have an array of hashes, each of which has non-normalized values like this:

```<code>arr = [{
    id: 0,
    type: 'character',
    person: {
      name: 'Steve Rogers',
      weapon: 'Shield',
      known: true
    }
  },
  {
    id: 1,
    type: 'organization',
    company: "Pym Industries",
    tech: 'Shrinking suit'
  },
  {
    id: 2,
    type: 'character',
    person: {
      name: 'Tony Stark',
      weapon: 'Ironman Suit',
      known: false
    }
  }]
</code>```

Some of the hashes are different. I want to get a subarray of hashes whose person I know, i.e., arr.person.known is true. The result should be like:

```<code>subarr = [{
    id: 0,
    type: 'character',
    person: {
      name: 'Steve Rogers',
      weapon: 'Shield',
      known: true
    }
  }]
</code>```

I tried:

```<code>b = arr.select{|x| x.person.known}
b = arr.reject{|x| if x.person then x.person.known}
</code>```

But I bump into NoMethodError: undefined method `person' for Hash:0x007fc5f6f587f0.

答:
Try this one

```<code>arr.select { |item| item.fetch(:person, {})[:known] }
</code>```

or

```<code>arr.select { |item| (item[:person] || {})[:known] }
</code>```

or, from Ruby 2.3.0

```<code>arr.select { |item| item.dig(:person, :known) }
</code>```

More verbose but maybe clearer

```<code>arr.select do |item|
  person = item.fetch(:person, {})
  person[:known]
end
</code>```

or

```<code>arr.select { |item| item[:person] && item[:person][:known] }
</code>```

Title: Search array of dissimilar hashes

Body:
I have an array of hashes, each of which has non-normalized values like this:

arr = [{
    id: 0,
    type: 'character',
    person: {
      name: 'Steve Rogers',
      weapon: 'Shield',
      known: true
    }
  },
  {
    id: 1,
    type: 'organization',
    company: "Pym Industries",
    tech: 'Shrinking suit'
  },
  {
    id: 2,
    type: 'character',
    person: {
      name: 'Tony Stark',
      weapon: 'Ironman Suit',
      known: false
    }
  }]

Some of the hashes are different. I want to get a subarray of hashes whose person I know, i.e., arr.person.known is true. The result should be like:

subarr = [{
    id: 0,
    type: 'character',
    person: {
      name: 'Steve Rogers',
      weapon: 'Shield',
      known: true
    }
  }]

I tried:

b = arr.select{|x| x.person.known}
b = arr.reject{|x| if x.person then x.person.known}

But I bump into NoMethodError: undefined method `person' for Hash:0x007fc5f6f587f0.

Body:
Try this one

arr.select { |item| item.fetch(:person, {})[:known] }

or

arr.select { |item| (item[:person] || {})[:known] }

or, from Ruby 2.3.0

arr.select { |item| item.dig(:person, :known) }

More verbose but maybe clearer

arr.select do |item|
  person = item.fetch(:person, {})
  person[:known]
end

or

arr.select { |item| item[:person] && item[:person][:known] }


问:
SSIS WMI event watcher WQL Direct Input query
I'm using SSIS in Visual Stdio 2010 to check a specific folder for any csv files that are dropped in from a 3rd party where the filename begins with 'Despatch'.  This is my WQL code:

```<code>   SELECT *
    FROM __InstanceCreationEvent WITHIN 5
    WHERE TargetInstance ISA 'CIM_DataFile'
        AND TargetInstance.Drive = 'E:'
        AND TargetInstance.Path = '\\Hybris URL REST Callbacks\\Despatched\\'
        AND TargetInstance.FileName LIKE 'Despatch%'
        AND TargetInstance.Extension = 'csv'
</code>```

However, when I run it, I just get the error "Invalid parameter".

If I modify to the below it works - but how do I search for despatch* csv files only?

```<code>SELECT * FROM __InstanceCreationEvent WITHIN 10
WHERE TargetInstance ISA "CIM_DirectoryContainsFile"
and TargetInstance.GroupComponent= "Win32_Directory.Name=\"e:\\\\Hybris URL REST Callbacks\\\\Despatched\""
</code>```

Where am I going wrong?

Regards,

Michael

答:
If anyone is interested I couldn't get this to work so using free SSIS file watcher addin:

http://www.sqlis.com/sqlis/post/File-Watcher-Task.aspx

Body:
I'm using SSIS in Visual Stdio 2010 to check a specific folder for any csv files that are dropped in from a 3rd party where the filename begins with 'Despatch'.  This is my WQL code:

   SELECT *
    FROM __InstanceCreationEvent WITHIN 5
    WHERE TargetInstance ISA 'CIM_DataFile'
        AND TargetInstance.Drive = 'E:'
        AND TargetInstance.Path = '\\Hybris URL REST Callbacks\\Despatched\\'
        AND TargetInstance.FileName LIKE 'Despatch%'
        AND TargetInstance.Extension = 'csv'

However, when I run it, I just get the error "Invalid parameter".

If I modify to the below it works - but how do I search for despatch* csv files only?

SELECT * FROM __InstanceCreationEvent WITHIN 10
WHERE TargetInstance ISA "CIM_DirectoryContainsFile"
and TargetInstance.GroupComponent= "Win32_Directory.Name=\"e:\\\\Hybris URL REST Callbacks\\\\Despatched\""

Where am I going wrong?

Regards,

Michael


问:
Pandas: display groupby aggregate statistic with data
Data Snippet

I am trying to add a new column to my data frame that displays the average purchase amount per user. The data frame is called trainDf and the below line of code produces the average by user. I'm trying to learn how to add it as a column to display similar  to the above image.

AveragePurchaseAmountUser = trainDf.groupby(by='User_ID')['Purchase_Amount'].mean()
```

Thank you in advance!

答:
This is what transform is for

```<code>AveragePurchaseAmountUser = trainDf.groupby(by='User_ID')['Purchase_Amount'].transform() .mean()
</code>```

I can't test atm, but you might need

```<code>...transform('mean')
</code>```

Instead

Body:
Data Snippet

I am trying to add a new column to my data frame that displays the average purchase amount per user. The data frame is called trainDf and the below line of code produces the average by user. I'm trying to learn how to add it as a column to display similar  to the above image.

AveragePurchaseAmountUser = trainDf.groupby(by='User_ID')['Purchase_Amount'].mean()

Thank you in advance!

Body:
This is what transform is for

AveragePurchaseAmountUser = trainDf.groupby(by='User_ID')['Purchase_Amount'].transform() .mean()

I can't test atm, but you might need

...transform('mean')

Instead


问:
How to close  tags using javascript?
I have a html string example as below:

```<code>html = "<html><body><img src = "" style = ""></body></html>
</code>```

How could I achieve the following:

```<code>html = "<html><body><img src = ""  style = ""></img></body></html>
</code>```

I want to close the image tags for a standard XHTML format. Would appreciate any suggestions. Thanks

答:
It's not clear what your question is. I read it one way, but I think Quentin's right that I should have read it another way.

The way I read it

...was that you wanted to know how to write an img tag in XHTML.

I want to close the image tags for a standard XHTML format.

In XHTML, void elements like img are written with a solidus (/) with a space in front of it prior to the > in the tag:

```<code>html = '<html><body><img src = ""  style = "" /></body></html>';
// ------------------------------------------^^
</code>```

(Note I changed to ' for the outer quotes, so that would be a syntactically-valid string.)

Since XHTML is XML and the spec doesn't impose any further syntax restrictions over XML's own, presumably you could also write . However, the XHTML 1 spec says you should use  instead because of "...uncertain results in many existing user agents."

Doing the  thing in HTML (not XHTML) is tolerated, but unnecessary.  is perfectly correct in HTML. (Note that this is only for void elements. The XHTML
 is correctly written

 in HTML, because div is not a void element;
 would be treated exactly like
 in HTML.)

Or possibly you meant...

...that you have a string with HTML in it, and want to modify it to be XHTML. If so, you want to use an HTML parser to parse the string, and then an XHTML serializer to turn it back into a string.

Title: How to close <img> tags using javascript?

Body:
I have a html string example as below:

html = "

How could I achieve the following:

html = "

I want to close the image tags for a standard XHTML format. Would appreciate any suggestions. Thanks

Body:
It's not clear what your question is. I read it one way, but I think Quentin's right that I should have read it another way.

The way I read it

...was that you wanted to know how to write an img tag in XHTML.

I want to close the image tags for a standard XHTML format.

In XHTML, void elements like img are written with a solidus (/) with a space in front of it prior to the > in the tag:

html = '<html><body><img src = ""  style = "" /></body></html>';
// ------------------------------------------^^

(Note I changed to ' for the outer quotes, so that would be a syntactically-valid string.)

Since XHTML is XML and the spec doesn't impose any further syntax restrictions over XML's own, presumably you could also write <img ...></img>. However, the XHTML 1 spec says you should use <img ... /> instead because of "...uncertain results in many existing user agents."

Doing the <img ... /> thing in HTML (not XHTML) is tolerated, but unnecessary. <img src = "" style = ""> is perfectly correct in HTML. (Note that this is only for void elements. The XHTML <div /> is correctly written <div></div> in HTML, because div is not a void element; <div /> would be treated exactly like <div> in HTML.)

Or possibly you meant...

...that you have a string with HTML in it, and want to modify it to be XHTML. If so, you want to use an HTML parser to parse the string, and then an XHTML serializer to turn it back into a string.


问:
How to style Form
I have a form in Laravel. I want to change the width of the form, because I want to put a other form next to it.

It looks like this

Which codes I should use in app.css? Any Suggestions? I tried codes in app.css but, maybe I should give a ID to form?

```<code>{!! Form::open(['method' => 'POST', 'action' => 'BusinessController@buy_energy']) !!}
<img src="images/foods/1.png" width="80px" height="80px"><br>
{!! Form::label('number', 'Ekmek(1 adt = 7 TL): ') !!}
{!! Form::number('number', 'value', ['min'=>1, 'max'=>10 ]) !!}
{!! Form::submit('Satın Al', ['class'=>'btn btn-primary']) !!}
</code>```

答:
In your blade add in the form the 'class' just like you add the action and the method:

```<code>{!! Form::open(['method' => 'POST', 'action' => 'BusinessController@buy_energy', 'class' => 'myForm']) !!}
<img src="images/foods/1.png" width="80px" height="80px"><br>
{!! Form::label('number', 'Ekmek(1 adt = 7 TL): ') !!}
{!! Form::number('number', 'value', ['min'=>1, 'max'=>10 ]) !!}
{!! Form::submit('Satın Al', ['class'=>'btn btn-primary']) !!}
</code>```

In your Css customize the myForm class:

```<code>.myForm{
   with: 400px;
}
</code>```

Title: How to style Form

Body:
I have a form in Laravel. I want to change the width of the form, because I want to put a other form next to it.

It looks like this

Which codes I should use in app.css? Any Suggestions? I tried codes in app.css but, maybe I should give a ID to form?

{!! Form::open(['method' => 'POST', 'action' => 'BusinessController@buy_energy']) !!}

{!! Form::label('number', 'Ekmek(1 adt = 7 TL): ') !!}
{!! Form::number('number', 'value', ['min'=>1, 'max'=>10 ]) !!}
{!! Form::submit('Satın Al', ['class'=>'btn btn-primary']) !!}

Body:
In your blade add in the form the 'class' just like you add the action and the method:

{!! Form::open(['method' => 'POST', 'action' => 'BusinessController@buy_energy', 'class' => 'myForm']) !!}
<img src="images/foods/1.png" width="80px" height="80px"><br>
{!! Form::label('number', 'Ekmek(1 adt = 7 TL): ') !!}
{!! Form::number('number', 'value', ['min'=>1, 'max'=>10 ]) !!}
{!! Form::submit('Satın Al', ['class'=>'btn btn-primary']) !!}

In your Css customize the myForm class:

.myForm{
   with: 400px;
}


答: It's working well for me, I even created a pdf from your text input and I copied the text back to a .txt file and it still working. I used Notepad++ to create my .txt file.</p>

Title: reading from a file(whose contents are copied from another file) in java


问:
SQL writing today -1460 days?
I have to change the code each day to make sure that is 4 years in the past based on list date. When I use '?' to set a parameter in excel it takes a long time to run. How can I hard code today -1460 days into this code? Below is current code. </p>

```<code>Select
MLB8.PROG_REPORT_ACCT_NUM_AND_PRACCT,
DCGI.Date_Listed,
DB.INITIAL_BALANCE,
DS.Last_Payment,
LV.Amt_Paid_On_Acct,
DB.Principal_Balance,
MLB7.INVENT_INVEN2
From
Clnt_General CG
Inner Join
Dbtr_Clnt_Generl_Inf DCGI on CG.Client_Num1=DCGI.Client
Inner Join
Dbtr_Status DS on DCGI.Account_Num1=DS.Account_Num1
Inner Join
Dbtr_Balances DB on DCGI.Account_Num1=DB.Account_Num1
Inner Join
Debtor_Master_Logic_Blocks7 MLB7 on DCGI.Account_Num1=MLB7.Account_Num1
Inner Join
Debtor_Master_Logic_Blocks8 MLB8 on DCGI.Account_Num1=MLB8.Account_Num1
Inner Join
Letter_Variables LV on DCGI.Account_Num1=LV.Account_Num1
Where
CG.Client_Num1=?
And
DCGI.Date_Listed>?
</code>```

答:
I hope I understood the question ... because it seems very simple ...</p>

```<code>DCGI.Date_Listed>= trunc(sysdate)-1460
</code>```

Title: SQL writing today -1460 days?

Body:
I have to change the code each day to make sure that is 4 years in the past based on list date. When I use '?' to set a parameter in excel it takes a long time to run. How can I hard code today -1460 days into this code? Below is current code.

Select
MLB8.PROG_REPORT_ACCT_NUM_AND_PRACCT,
DCGI.Date_Listed,
DB.INITIAL_BALANCE,
DS.Last_Payment,
LV.Amt_Paid_On_Acct,
DB.Principal_Balance,
MLB7.INVENT_INVEN2
From
Clnt_General CG
Inner Join
Dbtr_Clnt_Generl_Inf DCGI on CG.Client_Num1=DCGI.Client
Inner Join
Dbtr_Status DS on DCGI.Account_Num1=DS.Account_Num1
Inner Join
Dbtr_Balances DB on DCGI.Account_Num1=DB.Account_Num1
Inner Join
Debtor_Master_Logic_Blocks7 MLB7 on DCGI.Account_Num1=MLB7.Account_Num1
Inner Join
Debtor_Master_Logic_Blocks8 MLB8 on DCGI.Account_Num1=MLB8.Account_Num1
Inner Join
Letter_Variables LV on DCGI.Account_Num1=LV.Account_Num1
Where
CG.Client_Num1=?
And
DCGI.Date_Listed>?

Body:
I hope I understood the question ... because it seems very simple ...

DCGI.Date_Listed>= trunc(sysdate)-1460


问:
How to find prime numbers
Hi I'm writing in c language, below is my code. I'm trying to take in an input to check whether the person keying in a number is a prime number by using modulus.
However I'm getting error at the first if statement.
The error is floating point exception(core dumped)
why is this so? Am I not allowed to compare values with 0?

```<code>#include <stdio.h>

int main()
{
  int i = 0, j = 0, count = 0, value = 0, stop = 0;

      scanf("%d", &j);
      stop = j;
    for(i = 0; i < stop; ++i)
    {
      value = j % i;
      if(value == 0)
      {
        ++count;
      }
    }
    if(count>1)
      {
      printf("YES");
      }
      else
      printf("NO");
            return 0;

}
</code>```

Below is my question actually, I am not able to get my compile to work right although I can get the output.
Input

t – the number of test cases, then t test cases follows. [t <= 500]
Each line contains one integer: N [2 <= N <= 2^63-1]
Output

For each test case output string "YES" if given number is prime and "NO" otherwise.

```<code>#include <stdio.h>

int main()
{
  int i = 0, j = 0, count = 0, value = 0, stop = 0, store[]={0}, s = 0;

      scanf("%d", &j);
      stop = j;
    for(i = 1; i < stop; ++i)
    {
      value = j % i;
      if(value == 0)
      {
        store[s]=value;
        ++count;
        ++s;
      }
    }

    if(count>=2 || j==1 )
      {
      printf("NO");
      }
      else
      printf("YES");
    return 0;
}
</code>```

答:
I bet, you get the error ahead of the if statement at:

```<code>value = j % i;
</code>```

This is, because you start with i = 0:

```<code>for(i = 0; i < stop; ++i)
</code>```

Since the modulo operator % is a division, using 0 as second operand isn't legal. You get a divide by zero error.

BTW: Starting with 1 is meaningless.

Title: How to find prime numbers

Body:
Hi I'm writing in c language, below is my code. I'm trying to take in an input to check whether the person keying in a number is a prime number by using modulus.
However I'm getting error at the first if statement.
The error is floating point exception(core dumped)
why is this so? Am I not allowed to compare values with 0?

#include <stdio.h>

int main()
{
  int i = 0, j = 0, count = 0, value = 0, stop = 0;

      scanf("%d", &j);
      stop = j;
    for(i = 0; i < stop; ++i)
    {
      value = j % i;
      if(value == 0)
      {
        ++count;
      }
    }
    if(count>1)
      {
      printf("YES");
      }
      else
      printf("NO");
            return 0;

}

Below is my question actually, I am not able to get my compile to work right although I can get the output.
Input

t – the number of test cases, then t test cases follows. [t <= 500]
Each line contains one integer: N [2 <= N <= 2^63-1]
Output

For each test case output string "YES" if given number is prime and "NO" otherwise.

#include <stdio.h>

int main()
{
  int i = 0, j = 0, count = 0, value = 0, stop = 0, store[]={0}, s = 0;

      scanf("%d", &j);
      stop = j;
    for(i = 1; i < stop; ++i)
    {
      value = j % i;
      if(value == 0)
      {
        store[s]=value;
        ++count;
        ++s;
      }
    }

    if(count>=2 || j==1 )
      {
      printf("NO");
      }
      else
      printf("YES");
    return 0;
}

Body:
I bet, you get the error ahead of the if statement at:

value = j % i;

This is, because you start with i = 0:

for(i = 0; i < stop; ++i)

Since the modulo operator % is a division, using 0 as second operand isn't legal. You get a divide by zero error.

BTW: Starting with 1 is meaningless.


问:
Sending simple commands from Android through USB
I am a completely new at programming, and must get this task completed for a demonstration. I have a Samsung Captivate that I need to send simple messages to a device over USB. I'm not worried about having the droid act as host, not the issue here. I just need to find the proper code to access the USB functions in Android 2.1. I need to send simple on/off commands and audio level changes.

It would seem to me that this shouldn't be that hard, as the droid will communicate with my laptop and act as a storage device, so I know the two can talk. Can anybody help me find these  resources? I have been looking extensively, to no avail.

Thanks!

Bill

答: As Falmarri suggests, there is no access to USB from the SDK. From custom firmware, yes, but not the SDK.</p>


问:
Get UID firebase auth in variable
Is there a way to get your UID from firebase into a variable? I tried this but the variable is undefined.</p>

```<code>var userUID;

firebase.auth().onAuthStateChanged(function (user) {
    if (user) {
        userUID = user.uid;
    } else {}
});

console.log(userUID);
</code>```

答:
```<code>var userUID;
var user = firebase.auth().currentUser();

if (user)
  userUID = user.uid
</code>```

Title: Get UID firebase auth in variable

Body:
Is there a way to get your UID from firebase into a variable? I tried this but the variable is undefined.

var userUID;

firebase.auth().onAuthStateChanged(function (user) {
    if (user) {
        userUID = user.uid;
    } else {}
});

console.log(userUID);


问:
What is the correct way to add space to an HTML table?

I'm trying to adjust the spacing of a table in a webapp I'm building. I found various properties controlling space inside a table: cellspacing, cellpadding, border-spacing, and of course - margin and padding. What is the difference between those? Should I just use margin and padding which I know and understand, or is it more suitable and correct to use the table specific properties?  </p>

答:
As for cellpadding and cellspacing - they are not supported in HTML5 (See:
https://www.w3schools.com/tags/att_table_cellpadding.asp
https://www.w3schools.com/tags/att_table_cellspacing.asp). </p>

<p>As for the margin property, it can be used to space the whole table, but it does not apply for the space between cells (https://developer.mozilla.org/en-US/docs/Web/CSS/margin). For space between cells use the border-spacing property (https://www.w3schools.com/cssref/pr_border-spacing.asp). for space within cells simply use padding. </p>

Body:
As for cellpadding and cellspacing - they are not supported in HTML5 (See:
https://www.w3schools.com/tags/att_table_cellpadding.asp
https://www.w3schools.com/tags/att_table_cellspacing.asp).

As for the margin property, it can be used to space the whole table, but it does not apply for the space between cells (https://developer.mozilla.org/en-US/docs/Web/CSS/margin). For space between cells use the border-spacing property (https://www.w3schools.com/cssref/pr_border-spacing.asp). for space within cells simply use padding.


答:
userUID changes only after Auth object gets initialized, but you log it immediately at script execution.
Try to log it after Auth object gets initialized</p>

```<code>if (user) {
        userUID = user.uid;
        console.log(userUID);
    } else {}
</code>```

Title: Get UID firebase auth in variable

Body:
userUID changes only after Auth object gets initialized, but you log it immediately at script execution.
Try to log it after Auth object gets initialized

if (user) {
        userUID = user.uid;
        console.log(userUID);
    } else {}


问:
How to find the second minimum number without using arrays or loops
I tried to write a program that receive from the user 5 integers and print the second minimum number.

Here is a sample of what I've tried:

```<code>#include <iostream>
using namespace std;
int main () {
int a,b,c,d,e;
cin>>a>>b>>c>>d>>e;
if (a>b && a<c && a<d && a<e)
    cout<<a<<endl;
if (b>a && b<c && b<d && b<e)
    cout<<b<<endl;
if (c>a && c<b && c<d && c<e)
    cout<<c<<endl;
if (d>a && d<b && d<c && d<e)
    cout <<d<<endl;
if (e>a && e<b && e<c && e<d)
cout <<e<<endl;
return 0;

}
</code>```

When I enter 1 2 3 4 5 it prints the second minimum, but when I enter

5 4 3 2 1 Nothing will print on the screen. What am I doing wrong with this? Is there any other way to write my program?

答:
Update
In this solution I'm using the min function:

```<code>#include <iostream>
using namespace std;

int minDifferentFromFirstMin(int x, int y, int firstMin) {
    if(x < y) {
        if(x != firstMin) {
            return x;
        }
        else {
            return y;
         }
    }

    if(y < x) {
        if(y != firstMin) {
            return y;
        }
        else {
            return x;
         }
    }
    //if x & y are equals, return one of them
    return x;
}

int main () {
 int a,b,c,d,e;
 int iter11, iter12, iter13;
 int iter21, iter22, iter23;
 int firstMinimum, secondMinimum;
 cin>>a>>b>>c>>d>>e;

 //iteration 1: find the first minimum
 iter11 = min(a, b);
 iter12 = min(c, d);
 iter13 = min(iter11, iter12);
 firstMinimum = min(iter13, e);

 //iteration 2: find the second minimum
 iter21 = minDifferentFromFirstMin(a, b, firstMinimum);
 iter22 = minDifferentFromFirstMin(c, d, firstMinimum);
 iter23 = minDifferentFromFirstMin(iter21, iter22, firstMinimum);
 secondMinimum = minDifferentFromFirstMin(iter23, e, firstMinimum);

 cout<<secondMinimum<<endl;
}
</code>```

Body:
I tried to write a program that receive from the user 5 integers and print the second minimum number.

Here is a sample of what I've tried:

#include <iostream>
using namespace std;
int main () {
int a,b,c,d,e;
cin>>a>>b>>c>>d>>e;
if (a>b && a<c && a<d && a<e)
    cout<<a<<endl;
if (b>a && b<c && b<d && b<e)
    cout<<b<<endl;
if (c>a && c<b && c<d && c<e)
    cout<<c<<endl;
if (d>a && d<b && d<c && d<e)
    cout <<d<<endl;
if (e>a && e<b && e<c && e<d)
cout <<e<<endl;
return 0;

}

When I enter 1 2 3 4 5 it prints the second minimum, but when I enter

5 4 3 2 1 Nothing will print on the screen. What am I doing wrong with this? Is there any other way to write my program?

Body:
Update
In this solution I'm using the min function:

#include <iostream>
using namespace std;

int minDifferentFromFirstMin(int x, int y, int firstMin) {
    if(x < y) {
        if(x != firstMin) {
            return x;
        }
        else {
            return y;
         }
    }

    if(y < x) {
        if(y != firstMin) {
            return y;
        }
        else {
            return x;
         }
    }
    //if x & y are equals, return one of them
    return x;
}

int main () {
 int a,b,c,d,e;
 int iter11, iter12, iter13;
 int iter21, iter22, iter23;
 int firstMinimum, secondMinimum;
 cin>>a>>b>>c>>d>>e;

 //iteration 1: find the first minimum
 iter11 = min(a, b);
 iter12 = min(c, d);
 iter13 = min(iter11, iter12);
 firstMinimum = min(iter13, e);

 //iteration 2: find the second minimum
 iter21 = minDifferentFromFirstMin(a, b, firstMinimum);
 iter22 = minDifferentFromFirstMin(c, d, firstMinimum);
 iter23 = minDifferentFromFirstMin(iter21, iter22, firstMinimum);
 secondMinimum = minDifferentFromFirstMin(iter23, e, firstMinimum);

 cout<<secondMinimum<<endl;
}


问:
What are cgroups and how are people using them for cluster administration?
Are there examples of how people are using cgroups to better manage research computing clusters that runs parallel scientific codes and serial codes for an academic community?</p>

答:
The primary example I'm aware of is to be able set the cluster scheduler (e.g. Slurm) to assign multiple jobs to a single node without worrying about a renegade job utilizing more resources than assigned.

Cgroups is the mechanism so that the different jobs are only able to use the resources assigned to them by Slurm.

Prior to having cluster schedulers capable of doing this many HPC Centers only allowed either one job per node or one user per node.  Otherwise a job that requested only 1 core, for example, could, once running, actually use all the cores in the node which would cause other jobs on the node to run poorly.


问:
R, how to do anova in a loop over dataframe?
I would like to do 2ways anova, and store the p value and than do tukey hsd, but i have a problem with the initial table. Not always I have full data, so not always it is possible to perfors anova, I dont know how to do this so my script runs, than skip the not full data and runns further. my data looks like this:

https://filebin.net/w5cfuwztae7yk747

in the link there is example with two Accessions, but in real data there is 3013 accessions and some of them dont have all light conditions or all  genotypes

```<code>67822  AT2G41680        f      HL_f_Dejan58 1.240108e+06    HL      AT2G41680 f
 70136  AT2G41680        f     HL_f_Dejan_61 3.384010e+06    HL    AT2G41680 f
 72450  AT2G41680     ntrc HL_ntrc_ Dejan_62 1.410768e+05    HL AT2G41680 ntrc
 74764  AT2G41680     ntrc  HL_ntrc_Dejan_66 5.642197e+00    HL AT2G41680 ntrc
77078  AT2G41680     ntrc   HL_ntrc_Dejan65 3.921952e+05    HL AT2G41680 ntrc
 78997  AT2G41680       WT    LL_WT_Dejan_41 1.016001e+07    LL   AT2G41680 WT
 81433  AT2G41680       WT    LL_WT_Dejan_43 9.320892e+06    LL   AT2G41680 WT
 83869  AT2G41680       WT    LL_WT_Dejan_49 8.560308e+06    LL   AT2G41680 WT
</code>```

there is 4 genotypes, and four light conditions
I am trying to do something like this:

```<code>AOV<- data.frame()
IDs<- unique(Dejan_all_new_norm$Accession)
for (i in 1 : length(IDs)){
 temp<-Dejan_all_new_norm[(Dejan_all_new_norm$Accession)==IDs[i],]
    aov2<-aov(value ~ genotype + Light + genotype:Light, data = temp)
    AOV <- rbind(as.character(unique(IDs[i])),aov2,AOV)
}
</code>```

so i want to subset each gene (Accession) and than do ANOVA, but after this  i want do tukey to have something like this:

```<code>$`genotype:Light`
                    diff       lwr        upr     p adj
m:FL-f:FL        -7324259.81 -16715470  2066950.5 0.3486778
ntrc:FL-f:FL      1662873.54  -7728337 11054083.9 0.9999998
WT:FL-f:FL       -5219263.59 -13913835  3475307.7 0.7927417
f:HL-f:FL        -4936680.12 -13871535  3998174.3 0.8796738
m:HL-f:FL        -7389937.49 -16324792  1544916.9 0.2496858
ntrc:HL-f:FL     -7122962.46 -16057817  1811891.9 0.3102106
</code>```

I would like to work on this simple loop that is my example, because it seems easiest way.
I will appreciate any help!

Body:
I would like to do 2ways anova, and store the p value and than do tukey hsd, but i have a problem with the initial table. Not always I have full data, so not always it is possible to perfors anova, I dont know how to do this so my script runs, than skip the not full data and runns further. my data looks like this:

https://filebin.net/w5cfuwztae7yk747

in the link there is example with two Accessions, but in real data there is 3013 accessions and some of them dont have all light conditions or all  genotypes

67822  AT2G41680        f      HL_f_Dejan58 1.240108e+06    HL      AT2G41680 f
 70136  AT2G41680        f     HL_f_Dejan_61 3.384010e+06    HL    AT2G41680 f
 72450  AT2G41680     ntrc HL_ntrc_ Dejan_62 1.410768e+05    HL AT2G41680 ntrc
 74764  AT2G41680     ntrc  HL_ntrc_Dejan_66 5.642197e+00    HL AT2G41680 ntrc
77078  AT2G41680     ntrc   HL_ntrc_Dejan65 3.921952e+05    HL AT2G41680 ntrc
 78997  AT2G41680       WT    LL_WT_Dejan_41 1.016001e+07    LL   AT2G41680 WT
 81433  AT2G41680       WT    LL_WT_Dejan_43 9.320892e+06    LL   AT2G41680 WT
 83869  AT2G41680       WT    LL_WT_Dejan_49 8.560308e+06    LL   AT2G41680 WT

there is 4 genotypes, and four light conditions
I am trying to do something like this:

AOV<- data.frame()
IDs<- unique(Dejan_all_new_norm$Accession)
for (i in 1 : length(IDs)){
 temp<-Dejan_all_new_norm[(Dejan_all_new_norm$Accession)==IDs[i],]
    aov2<-aov(value ~ genotype + Light + genotype:Light, data = temp)
    AOV <- rbind(as.character(unique(IDs[i])),aov2,AOV)
}

so i want to subset each gene (Accession) and than do ANOVA, but after this  i want do tukey to have something like this:

$`genotype:Light`
                    diff       lwr        upr     p adj
m:FL-f:FL        -7324259.81 -16715470  2066950.5 0.3486778
ntrc:FL-f:FL      1662873.54  -7728337 11054083.9 0.9999998
WT:FL-f:FL       -5219263.59 -13913835  3475307.7 0.7927417
f:HL-f:FL        -4936680.12 -13871535  3998174.3 0.8796738
m:HL-f:FL        -7389937.49 -16324792  1544916.9 0.2496858
ntrc:HL-f:FL     -7122962.46 -16057817  1811891.9 0.3102106

I would like to work on this simple loop that is my example, because it seems easiest way.
I will appreciate any help!

Body:
Is this what you are looking for:

library(tidyverse)
library(broom)

read_csv(file = "https://filebin.net/w5cfuwztae7yk747/two.csv") %>%
  group_by(Accession) %>%
  do(broom::tidy(TukeyHSD(aov(value ~ genotype + Light + genotype:Light, data = .)))) %>%
  ungroup

Output:

# A tibble: 264 x 7
   Accession     term comparison    estimate   conf.low  conf.high  adj.p.value
   <chr>   <fctr>      <chr>       <dbl>      <dbl>      <dbl>        <dbl>
 1 AT2G41680 genotype        m-f -1586182.59 -3616647.7   444282.5 1.708496e-01
 2 AT2G41680 genotype     ntrc-f -5705550.95 -7694992.3 -3716109.6 2.609223e-08
 3 AT2G41680 genotype       WT-f -1568375.95 -3557817.3   421065.4 1.647950e-01
 4 AT2G41680 genotype     ntrc-m -4119368.37 -6149833.5 -2088903.3 2.214399e-05
 5 AT2G41680 genotype       WT-m    17806.64 -2012658.5  2048271.8 9.999951e-01
 6 AT2G41680 genotype    WT-ntrc  4137175.00  2147733.6  6126616.4 1.464605e-05
 7 AT2G41680    Light      HL-FL -3854435.85 -5849789.4 -1859082.3 4.872013e-05
 8 AT2G41680    Light      LL-FL  1528123.46  -467230.1  3523477.0 1.844033e-01
 9 AT2G41680    Light      ML-FL -2821752.94 -4775345.6  -868160.3 2.283331e-03
10 AT2G41680    Light      LL-HL  5382559.31  3311883.1  7453235.6 2.176770e-07
# ... with 254 more rows


问:
CKEditor with jQuery UI Dialog, spell check and buttons not working on second click
I'm using CKEditor 4 to turn a <textarea> into a WYSIWYG editor inside a jQuery UI Dialog.

I have 3 issues which I'm assuming are related:

The SCAYT feature isn't working. You can click the spell check dropdown and click "Enable SCAYT" but it doesn't do anything.

If you click the "Enable SCAYT" option twice, you'll get JS errors saying the version of SCAYT is newer than the application version and that SCAYT is undefined:

If you close the dialog and try to re-open it, the JS error repeats itself and most of the other buttons stop working:

Any help would be great. Here's the code I'm using:

```<code>function OpenDialog(modalID, w, h) {
    $("#" + modalID).css("display", "block");

    $("#" + modalID).dialog({
        draggable: false,
        height: h,
        width: w,
        resizable: false,
        modal: true,
        appendTo: "form",
        buttons: [
            {
                text: 'Save',
                class: "saveicon",
                click: function () {
                    //Save Stuff
                }
            }
        ]
    }).bind('dialogclose', function (event, ui) {
        //toggles the editor controls
        editor = CKEDITOR.instances['<%=txtEditor.ClientID %>'];
        if (editor) {
            editor.updateElement();
            editor.destroy();
        }
    });
    $(".saveicon").prepend('<span class="glyphicon glyphicon-floppy-disk"></span> ');
}
</code>```

答:
My problem was a combination of issues, all on my end:

The buttons graying out was due to a cache problem. I cleared my cache and the problem was resolved.

The SCAYT issue was because my company's firewall was blocking the call to the SCAYT web service.

Body:
I'm using CKEditor 4 to turn a <textarea> into a WYSIWYG editor inside a jQuery UI Dialog.

I have 3 issues which I'm assuming are related:

The SCAYT feature isn't working. You can click the spell check dropdown and click "Enable SCAYT" but it doesn't do anything.

If you click the "Enable SCAYT" option twice, you'll get JS errors saying the version of SCAYT is newer than the application version and that SCAYT is undefined:

If you close the dialog and try to re-open it, the JS error repeats itself and most of the other buttons stop working:

Any help would be great. Here's the code I'm using:

function OpenDialog(modalID, w, h) {
    $("#" + modalID).css("display", "block");

    $("#" + modalID).dialog({
        draggable: false,
        height: h,
        width: w,
        resizable: false,
        modal: true,
        appendTo: "form",
        buttons: [
            {
                text: 'Save',
                class: "saveicon",
                click: function () {
                    //Save Stuff
                }
            }
        ]
    }).bind('dialogclose', function (event, ui) {
        //toggles the editor controls
        editor = CKEDITOR.instances['<%=txtEditor.ClientID %>'];
        if (editor) {
            editor.updateElement();
            editor.destroy();
        }
    });
    $(".saveicon").prepend(' ');
}


问:
Error to install pip on google-cloud
)
I tried to install pip on a gcloud server with ubunto 16.04
I got this error massage. Hopefuly you can help me.

https://pastebin.com/Pdyt5n5j

maybe pastbin is better to read.

root@bascic:~/gcloudstuff# sudo apt-get install python-pip
Reading package lists... Done
Building dependency tree

Reading state information... Done
The following additional packages will be installed:
  binutils build-essential cpp cpp-5 dpkg-dev fakeroot g++ g++-5 gcc gcc-5 libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan2 libatomic1 libc-dev-bin libc6-dev libcc1-0 libcilkrts5
  libdpkg-perl libexpat1-dev libfakeroot libfile-fcntllock-perl libgcc-5-dev libgomp1 libisl15 libitm1 liblsan0
  libmpc3 libmpx0 libpython-all-dev libpython-dev libpython2.7 libpython2.7-dev libquadmath0 libstdc++-5-dev libtsan0
  libubsan0 linux-libc-dev make manpages-dev python-all python-all-dev python-dev python-pip-whl python-setuptools
  python-wheel python2.7-dev
Suggested packages:
  binutils-doc cpp-doc gcc-5-locales debian-keyring g++-multilib g++-5-multilib gcc-5-doc libstdc++6-5-dbg
  gcc-multilib autoconf automake libtool flex bison gdb gcc-doc gcc-5-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg
  libatomic1-dbg libasan2-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx0-dbg libquadmath0-dbg
  glibc-doc libstdc++-5-doc make-doc python-setuptools-doc
The following NEW packages will be installed:
  binutils build-essential cpp cpp-5 dpkg-dev fakeroot g++ g++-5 gcc gcc-5 libalgorithm-diff-perl
  libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan2 libatomic1 libc-dev-bin libc6-dev libcc1-0 libcilkrts5
  libdpkg-perl libexpat1-dev libfakeroot libfile-fcntllock-perl libgcc-5-dev libgomp1 libisl15 libitm1 liblsan0
  libmpc3 libmpx0 libpython-all-dev libpython-dev libpython2.7 libpython2.7-dev libquadmath0 libstdc++-5-dev libtsan0
  libubsan0 linux-libc-dev make manpages-dev python-all python-all-dev python-dev python-pip python-pip-whl
  python-setuptools python-wheel python2.7-dev
0 upgraded, 49 newly installed, 0 to remove and 0 not upgraded.
Need to get 837 kB/69.0 MB of archives.
After this operation, 192 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Err:1 http://security.ubuntu.com/ubuntu xenial-security/main amd64 linux-libc-dev amd64 4.4.0-71.92
  404  Not Found [IP: 192.158.31.252 80]
Err:1 http://security.ubuntu.com/ubuntu xenial-security/main amd64 linux-libc-dev amd64 4.4.0-71.92
  404  Not Found [IP: 192.158.31.252 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/l/linux/linux-libc-dev_4.4.0-71.92_amd64.deb  404  Not F
ound [IP: 192.158.31.252 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

答:
I have seen the same error message, but could solve it by running:

```<code>sudo apt-get update
</code>```

Afterwards, I could install pip/pip3 without any issue:

```<code>sudo apt-get install python3-pip
</code>```

Title: Error to install pip on google-cloud

Body:
I have seen the same error message, but could solve it by running:

sudo apt-get update

Afterwards, I could install pip/pip3 without any issue:

sudo apt-get install python3-pip


问:
Is it faster to use two separate SQL statements or one SQL statement with JOIN?
I'm in doubt about the performance by "two or more individual SQL commands" or "1 but using 'join' SQL command".

Here is the thing:

For example, I have two tables: post, user

post has a user_id indicating this post is issued by some user in user

and I'm going to extract both post and username.

I can either

```
SELECT * FROM `post` LEFT JOIN `user` on post.user_id = user.id WHERE 1
```

or

```
$rows = $db->sql("SELEFT * FROM `post` WHERE 1")
for $row in $rows:
    $db->sql("SELECT * FROM `user` WHERE id = $row['user_id']")
```

I'm wondering which one will have better performance?

And what if I have 3 or more tables to join, which way will be better (from the performance perspective)?

答: The LEFT JOIN is strongly recommended because otherwise putting a query inside a loop (as in the second example) will multiple the hit on your database, which is also a dangerous situation.</p>

Body:
I'm in doubt about the performance by "two or more individual SQL commands" or "1 but using 'join' SQL command".

Here is the thing:

For example, I have two tables: post, user

post has a user_id indicating this post is issued by some user in user

and I'm going to extract both post and username.

I can either

SELECT * FROM `post` LEFT JOIN `user` on post.user_id = user.id WHERE 1

or

$rows = $db->sql("SELEFT * FROM `post` WHERE 1")
for $row in $rows:
    $db->sql("SELECT * FROM `user` WHERE id = $row['user_id']")

I'm wondering which one will have better performance?

And what if I have 3 or more tables to join, which way will be better (from the performance perspective)?


问:
How to read the new line between multi-valued enumerate that has been turned into a string using ""
I have an enumerate-type multi-valued attribute in the module in which I am working.

The appearance is as follows:

```<code>// as it appears in the attribute column
val1
vals-2
vals3
// below is what is written in my script to turn the contents this attribute
// into a string (for this particular object)
string ovp = o."AttribName" // I have assigned it to a string in this manner
</code>```

If I print the string, it prints out in a column format, like it appears in the attribute column.  How has the new line been defined in this string?

I would like to use the new line definition to put each of the enumerate values into a string array (string arr[size], for clarity as I may not be using the right terms).

I am sure there is a way, but I am only two weeks into using DXL, and am at a loss on how to do this, or if there would be another way to do it that might be easier.

I have searched as much as I am able with the keywords that I know.

Thanks in advance for any help or direction.  I will keep trying in the mean-time and see what I come up with. I assume that if I find an answer, I can update this question with it.

答:
So there is probably a better way to do this, by querying the attribute definition and then using the 'isMember' function- but this way will return a string array, which you requested.

```<code>Object o = current

string s = o."Test Enum" ""

int x = 0
int y = 0
int size = 0

if ( s != "" ) {
    size++
}
for ( x = 0 ; x < length ( s ) ; x++ ) {
    if ( s [ x ] == '\n' ) {
        size++
    }

}
string arr[size]
size = 0
for ( x = 0 ; x < length ( s ) ; x++ ) {
    if ( s [ x ] == '\n' ) {
        arr[ size ] = s [ y : x - 1 ]
        y = x + 1
        size++
    }
}
arr[ size ] = s [ y : ]
</code>```

Of note- this first checks the size of the array, then defines it. Multiple selected attributes have a '\n' as a delimiter, but the last entry won't have that.

Body:
I have an enumerate-type multi-valued attribute in the module in which I am working.

The appearance is as follows:

// as it appears in the attribute column
val1
vals-2
vals3
// below is what is written in my script to turn the contents this attribute
// into a string (for this particular object)
string ovp = o."AttribName" // I have assigned it to a string in this manner

If I print the string, it prints out in a column format, like it appears in the attribute column.  How has the new line been defined in this string?

I would like to use the new line definition to put each of the enumerate values into a string array (string arr[size], for clarity as I may not be using the right terms).

I am sure there is a way, but I am only two weeks into using DXL, and am at a loss on how to do this, or if there would be another way to do it that might be easier.

I have searched as much as I am able with the keywords that I know.

Thanks in advance for any help or direction.  I will keep trying in the mean-time and see what I come up with. I assume that if I find an answer, I can update this question with it.

Body:
So there is probably a better way to do this, by querying the attribute definition and then using the 'isMember' function- but this way will return a string array, which you requested.

Object o = current

string s = o."Test Enum" ""

int x = 0
int y = 0
int size = 0

if ( s != "" ) {
    size++
}
for ( x = 0 ; x < length ( s ) ; x++ ) {
    if ( s [ x ] == '\n' ) {
        size++
    }

}
string arr[size]
size = 0
for ( x = 0 ; x < length ( s ) ; x++ ) {
    if ( s [ x ] == '\n' ) {
        arr[ size ] = s [ y : x - 1 ]
        y = x + 1
        size++
    }
}
arr[ size ] = s [ y : ]

Of note- this first checks the size of the array, then defines it. Multiple selected attributes have a '\n' as a delimiter, but the last entry won't have that.


问:
Angular response is undefined
Trying to retrieve using angular the json found at: "https://api.github.com/users/angular", more precisely the id property from that json.
Any thoughts on why this fails (in debug mode I get a

'response is not defined'

):

```<code><html ng-app="myViewer">
<head>
<script data-require="angular.js@*" data-semver="1.2.25" src="https://code.angularjs.org/1.2.25/angular.js"></script>
</head>

<body ng-controller="MyController">
    {{ result.id }}
    {{ err }}
</body>

<script type="text/javascript">
(function() {

    var app = angular.module("myViewer", []);

    var MyController = function($scope, $http)
    {
        $http.get("https://api.github.com/users/angular")
        .then(function1, onerr);

        var function1 = function(response)
        {
            $scope.result = response.data;
        }
        var onerr = function(reason)
        {
            $scope.err = "nightmare";
        }

    }

    app.controller("MyController", ["$scope", "$http", MyController]);
}());

</script>
</html>
</code>```

I expect the result to be the id that you can see by copying that link in your browser.

答:
Try with following

var function1 = function(response) { $scope.result = response; }

Title: Angular response is undefined

Body:
Trying to retrieve using angular the json found at: "https://api.github.com/users/angular", more precisely the id property from that json.
Any thoughts on why this fails (in debug mode I get a

'response is not defined'

):

    {{ result.id }}
    {{ err }}

I expect the result to be the id that you can see by copying that link in your browser.


问:
OperationalError: foreign key mismatch
I have two tables that I'm filling, 'msrun' and 'feature'. 'feature' has a foreign key pointing to the 'msrun_name' column of the 'msrun' table. Inserting in the tables works fine. But when I try to delete from the 'feature' table I get the following error:

```<code>pysqlite2.dbapi2.OperationalError: foreign key mismatch
</code>```

From the rules of foreign keys in the manual of SQLite:

```<code>- The parent table does not exist, or
- The parent key columns named in the foreign key constraint do not exist, or
- The parent key columns named in the foreign key constraint are not the primary key of the parent table and are not subject to a unique constraint using collating sequence specified in the CREATE TABLE, or
- The child table references the primary key of the parent without specifying the primary key columns and the number of primary key columns in the parent do not match the number of child key columns.
</code>```

I can see nothing that I'm violating. My create tables look like this:

```<code>DROP TABLE IF EXISTS `msrun`;
-- -----------------------------------------------------
-- Table `msrun`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `msrun` (
  `msrun_name` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `description` VARCHAR(500) NOT NULL );

DROP TABLE IF EXISTS `feature`;
-- -----------------------------------------------------
-- Table `feature`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature` (
  `feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `intensity` DOUBLE NOT NULL ,
  `overallquality` DOUBLE NOT NULL ,
  `charge` INT NOT NULL ,
  `content` VARCHAR(45) NOT NULL ,
  `msrun_msrun_name` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_feature_msrun1`
    FOREIGN KEY (`msrun_msrun_name` )
    REFERENCES `msrun` (`msrun_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE UNIQUE INDEX `id_UNIQUE` ON `feature` (`feature_id` ASC);
  CREATE INDEX `fk_feature_msrun1` ON `feature` (`msrun_msrun_name` ASC);
</code>```

As far as I can see the parent table exists, the foreign key is pointing to the right parent key, the parent key is a primary key and the foreign key specifies the primary key column.

The script that produces the error:

```<code>from pysqlite2 import dbapi2 as sqlite
import parseFeatureXML

connection = sqlite.connect('example.db')
cursor = connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")

inputValues = ('example', 'description')
cursor.execute("INSERT INTO `msrun` VALUES(?, ?)", inputValues)
featureXML = parseFeatureXML.Reader('../example_scripts/example_files/input/featureXML_example.featureXML')

for feature in featureXML.getSimpleFeatureInfo():
    inputValues = (featureXML['id'], featureXML['intensity'],
                   featureXML['overallquality'], featureXML['charge'],
                   featureXML['content'], 'example')
    # insert the values into msrun using ? for sql injection safety
    cursor.execute("INSERT INTO `feature` VALUES(?,?,?,?,?,?)", inputValues)
connection.commit()

for feature in featureXML.getSimpleFeatureInfo():
    cursor.execute("DELETE FROM `feature` WHERE feature_id = ?", (str(featureXML['id']),))
</code>```

Edit:

These are the tables that have foreign keys linking to features. They are not being filled  yet:

```<code>DROP TABLE IF EXISTS `convexhull`;
-- -----------------------------------------------------
-- Table `convexhull`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `convexhull` (
  `convexhull_id` INT PRIMARY KEY NOT NULL ,
  `mz` DOUBLE NOT NULL ,
  `rt` DOUBLE NOT NULL ,
  `feature_feature_id` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_convexhull_feature`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_convexhull_feature` ON `convexhull` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `position`;
-- -----------------------------------------------------
-- Table `position`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `position` (
  `position_id` INT PRIMARY KEY NOT NULL ,
  `dim0` INT NOT NULL ,
  `dim1` INT NOT NULL ,
  `feature_feature_id` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_position_feature1`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_position_feature1` ON `position` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `userParam_names`;
-- -----------------------------------------------------
-- Table `userParam_names`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `userParam_names` (
  `userParam_id` INT PRIMARY KEY NOT NULL ,
  `Name` VARCHAR(45) NOT NULL );

DROP TABLE IF EXISTS `feature_has_userParam_names`;
-- -----------------------------------------------------
-- Table IF EXISTS `feature_has_userParam_names`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature_has_userParam_names` (
  `feature_feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `userParam_names_userParam_id` INT NOT NULL ,
  CONSTRAINT `fk_feature_has_userParam_names_feature1`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_feature_has_userParam_names_userParam_names1`
    FOREIGN KEY (`userParam_names_userParam_id` )
    REFERENCES `userParam_names` (`userParam_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_feature_has_userParam_names_userParam_names1` ON `feature_has_userParam_names` (`userParam_names_userParam_id` ASC);
  CREATE INDEX `fk_feature_has_userParam_names_feature1` ON `feature_has_userParam_names` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `userParam_value`;
-- -----------------------------------------------------
-- Table IF EXISTS `userParam_value`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `userParam_value` (
  `iduserParam_value` INT PRIMARY KEY NOT NULL ,
  `userParam_name` VARCHAR(45) NOT NULL ,
  `value` VARCHAR(45) NOT NULL );

DROP TABLE IF EXISTS `feature_has_userParam_names_has_userParam_value`;
-- -----------------------------------------------------
-- Table `feature_has_userParam_names_has_userParam_value`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature_has_userParam_names_has_userParam_value` (
  `feature_has_userParam_names_feature_feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `feature_has_userParam_names_userParam_names_userParam_id` INT NOT NULL ,
  `userParam_value_iduserParam_value` INT NOT NULL ,
  CONSTRAINT `fk_feature_has_userParam_names_has_userParam_value_feature_ha1`
    FOREIGN KEY (`feature_has_userParam_names_feature_feature_id` , `feature_has_userParam_names_userParam_names_userParam_id` )
    REFERENCES `feature_has_userParam_names` (`feature_feature_id` , `userParam_names_userParam_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_feature_has_userParam_names_has_userParam_value_userParam_1`
    FOREIGN KEY (`userParam_value_iduserParam_value` )
    REFERENCES `userParam_value` (`iduserParam_value` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_feature_has_userParam_names_has_userParam_value_userParam_1` ON  `feature_has_userParam_names_has_userParam_value` (`userParam_value_iduserParam_value` ASC);
  CREATE INDEX `fk_feature_has_userParam_names_has_userParam_value_feature_ha1` ON  `feature_has_userParam_names_has_userParam_value` (`feature_has_userParam_names_feature_feature_id` ASC, `feature_has_userParam_names_userParam_names_userParam_id` ASC);
</code>```

The delete statement does work when I do it from SQLite manager.

edit 2:

Full traceback:

```<code>Traceback (most recent call last):
  File "/homes/ndeklein/workspace/MS/Trunk/PyMS_dev/database/test.py", line 25, in <module>
    cursor.execute("DELETE FROM `feature` WHERE feature_id = 'f_13020522388175237334'")
pysqlite2.dbapi2.OperationalError: foreign key mismatch
</code>```

Doing

```<code>DELETE FROM `feature` WHERE feature_id = 'f_13020522388175237334'
</code>```

in SQLite Manager works.

Edit 3

Including all tables:

```<code>--------------------------------------------------------
-- pyMS database. Drops all tables before it makes them, should be changed before release
--------------------------------------------------------

DROP TABLE IF EXISTS `msrun`;
-- -----------------------------------------------------
-- Table `msrun`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `msrun` (
  `msrun_name` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `description` VARCHAR(500) NOT NULL );

DROP TABLE IF EXISTS `feature`;
-- -----------------------------------------------------
-- Table `feature`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature` (
  `feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `intensity` DOUBLE NOT NULL ,
  `overallquality` DOUBLE NOT NULL ,
  `charge` INT NOT NULL ,
  `content` VARCHAR(45) NOT NULL ,
  `msrun_msrun_name` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_feature_msrun1`
    FOREIGN KEY (`msrun_msrun_name` )
    REFERENCES `msrun` (`msrun_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE UNIQUE INDEX `id_UNIQUE` ON `feature` (`feature_id` ASC);
  CREATE INDEX `fk_feature_msrun1` ON `feature` (`msrun_msrun_name` ASC);

DROP TABLE IF EXISTS `convexhull`;
-- -----------------------------------------------------
-- Table `convexhull`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `convexhull` (
  `convexhull_id` INT PRIMARY KEY NOT NULL ,
  `mz` DOUBLE NOT NULL ,
  `rt` DOUBLE NOT NULL ,
  `feature_feature_id` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_convexhull_feature`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_convexhull_feature` ON `convexhull` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `position`;
-- -----------------------------------------------------
-- Table `position`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `position` (
  `position_id` INT PRIMARY KEY NOT NULL ,
  `dim0` INT NOT NULL ,
  `dim1` INT NOT NULL ,
  `feature_feature_id` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_position_feature1`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_position_feature1` ON `position` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `userParam_names`;
-- -----------------------------------------------------
-- Table `userParam_names`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `userParam_names` (
  `userParam_id` INT PRIMARY KEY NOT NULL ,
  `Name` VARCHAR(45) NOT NULL );

DROP TABLE IF EXISTS `feature_has_userParam_names`;
-- -----------------------------------------------------
-- Table IF EXISTS `feature_has_userParam_names`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature_has_userParam_names` (
  `feature_feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `userParam_names_userParam_id` INT NOT NULL ,
  CONSTRAINT `fk_feature_has_userParam_names_feature1`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_feature_has_userParam_names_userParam_names1`
    FOREIGN KEY (`userParam_names_userParam_id` )
    REFERENCES `userParam_names` (`userParam_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_feature_has_userParam_names_userParam_names1` ON `feature_has_userParam_names` (`userParam_names_userParam_id` ASC);
  CREATE INDEX `fk_feature_has_userParam_names_feature1` ON `feature_has_userParam_names` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `userParam_value`;
-- -----------------------------------------------------
-- Table IF EXISTS `userParam_value`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `userParam_value` (
  `iduserParam_value` INT PRIMARY KEY NOT NULL ,
  `userParam_name` VARCHAR(45) NOT NULL ,
  `value` VARCHAR(45) NOT NULL );

DROP TABLE IF EXISTS `feature_has_userParam_names_has_userParam_value`;
-- -----------------------------------------------------
-- Table `feature_has_userParam_names_has_userParam_value`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature_has_userParam_names_has_userParam_value` (
  `feature_has_userParam_names_feature_feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `feature_has_userParam_names_userParam_names_userParam_id` INT NOT NULL ,
  `userParam_value_iduserParam_value` INT NOT NULL ,
  CONSTRAINT `fk_feature_has_userParam_names_has_userParam_value_feature_ha1`
    FOREIGN KEY (`feature_has_userParam_names_feature_feature_id` , `feature_has_userParam_names_userParam_names_userParam_id` )
    REFERENCES `feature_has_userParam_names` (`feature_feature_id` , `userParam_names_userParam_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_feature_has_userParam_names_has_userParam_value_userParam_1`
    FOREIGN KEY (`userParam_value_iduserParam_value` )
    REFERENCES `userParam_value` (`iduserParam_value` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_feature_has_userParam_names_has_userParam_value_userParam_1` ON  `feature_has_userParam_names_has_userParam_value` (`userParam_value_iduserParam_value` ASC);
  CREATE INDEX `fk_feature_has_userParam_names_has_userParam_value_feature_ha1` ON  `feature_has_userParam_names_has_userParam_value` (`feature_has_userParam_names_feature_feature_id` ASC, `feature_has_userParam_names_userParam_names_userParam_id` ASC);

DROP TABLE IF EXISTS `precursor`;
-- -----------------------------------------------------
-- Table `precursor`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `precursor` (
  `precursor_id` INT PRIMARY KEY NOT NULL ,
  `ion_mz` DOUBLE NOT NULL ,
  `charge_state` INT NOT NULL ,
  `peak_intensity` DOUBLE NOT NULL );

DROP TABLE IF EXISTS `spectrum`;
-- -----------------------------------------------------
-- Table `spectrum`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `spectrum` (
  `spectrum_index` INT PRIMARY KEY NOT NULL ,
  `ms_level` INT NOT NULL ,
  `base_peak_mz` DOUBLE NOT NULL ,
  `base_peak_intensity` DOUBLE NOT NULL ,
  `total_ion_current` DOUBLE NOT NULL ,
  `lowest_observes_mz` DOUBLE NOT NULL ,
  `highest_observed_mz` DOUBLE NOT NULL ,
  `scan_start_time` DOUBLE NOT NULL ,
  `ion_injection_time` DOUBLE NOT NULL ,
  `msrun_msrun_name` VARCHAR(40) NOT NULL ,
  `precursor_precursor_id` INT NOT NULL ,
  CONSTRAINT `fk_spectrum_msrun1`
    FOREIGN KEY (`msrun_msrun_name` )
    REFERENCES `msrun` (`msrun_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_spectrum_precursor1`
    FOREIGN KEY (`precursor_precursor_id` )
    REFERENCES `precursor` (`precursor_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_spectrum_msrun1` ON `spectrum` (`msrun_msrun_name` ASC);
  CREATE INDEX `fk_spectrum_precursor1` ON `spectrum` (`precursor_precursor_id` ASC);

DROP TABLE IF EXISTS `spectrum_has_feature`;
-- -----------------------------------------------------
-- Table `spectrum_has_feature`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `spectrum_has_feature` (
  `spectrum_spectrum_index` INT PRIMARY KEY NOT NULL ,
  `spectrum_msrun_msrun_name` VARCHAR(40) NOT NULL ,
  `spectrum_precursor_precursor_id` INT NOT NULL ,
  `feature_feature_id` VARCHAR(40) NOT NULL ,
  `feature_msrun_msrun_name` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_spectrum_has_feature_spectrum1`
    FOREIGN KEY (`spectrum_spectrum_index` , `spectrum_msrun_msrun_name` , `spectrum_precursor_precursor_id` )
    REFERENCES `spectrum` (`spectrum_index` , `msrun_msrun_msrun_name` , `precursor_precursor_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_spectrum_has_feature_feature1`
    FOREIGN KEY (`feature_feature_id` , `feature_msrun_msrun_name` )
    REFERENCES `feature` (`feature_id` , `msrun_msrun_msrun_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_spectrum_has_feature_feature1` ON `spectrum_has_feature` (`feature_feature_id` ASC, `feature_msrun_msrun_name` ASC);
  CREATE INDEX `fk_spectrum_has_feature_spectrum1` ON `spectrum_has_feature` (`spectrum_spectrum_index` ASC, `spectrum_msrun_msrun_name` ASC, `spectrum_precursor_precursor_id` ASC);
</code>```

答:
I landed here after updating to Django==2.0.
My required fix was just to drop all the migrations I had written with Django==1.11.6 and run a new makemigrations with 2.0.
Of course, I couldn't have done this had I had any database hosting my app requiring the migration files to be maintained

Title: OperationalError: foreign key mismatch

Body:
I have two tables that I'm filling, 'msrun' and 'feature'. 'feature' has a foreign key pointing to the 'msrun_name' column of the 'msrun' table. Inserting in the tables works fine. But when I try to delete from the 'feature' table I get the following error:

pysqlite2.dbapi2.OperationalError: foreign key mismatch

From the rules of foreign keys in the manual of SQLite:

- The parent table does not exist, or
- The parent key columns named in the foreign key constraint do not exist, or
- The parent key columns named in the foreign key constraint are not the primary key of the parent table and are not subject to a unique constraint using collating sequence specified in the CREATE TABLE, or
- The child table references the primary key of the parent without specifying the primary key columns and the number of primary key columns in the parent do not match the number of child key columns.

I can see nothing that I'm violating. My create tables look like this:

DROP TABLE IF EXISTS `msrun`;
-- -----------------------------------------------------
-- Table `msrun`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `msrun` (
  `msrun_name` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `description` VARCHAR(500) NOT NULL );

DROP TABLE IF EXISTS `feature`;
-- -----------------------------------------------------
-- Table `feature`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature` (
  `feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `intensity` DOUBLE NOT NULL ,
  `overallquality` DOUBLE NOT NULL ,
  `charge` INT NOT NULL ,
  `content` VARCHAR(45) NOT NULL ,
  `msrun_msrun_name` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_feature_msrun1`
    FOREIGN KEY (`msrun_msrun_name` )
    REFERENCES `msrun` (`msrun_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE UNIQUE INDEX `id_UNIQUE` ON `feature` (`feature_id` ASC);
  CREATE INDEX `fk_feature_msrun1` ON `feature` (`msrun_msrun_name` ASC);

As far as I can see the parent table exists, the foreign key is pointing to the right parent key, the parent key is a primary key and the foreign key specifies the primary key column.

The script that produces the error:

from pysqlite2 import dbapi2 as sqlite
import parseFeatureXML

connection = sqlite.connect('example.db')
cursor = connection.cursor()
cursor.execute("PRAGMA foreign_keys=ON")

inputValues = ('example', 'description')
cursor.execute("INSERT INTO `msrun` VALUES(?, ?)", inputValues)
featureXML = parseFeatureXML.Reader('../example_scripts/example_files/input/featureXML_example.featureXML')

for feature in featureXML.getSimpleFeatureInfo():
    inputValues = (featureXML['id'], featureXML['intensity'],
                   featureXML['overallquality'], featureXML['charge'],
                   featureXML['content'], 'example')
    # insert the values into msrun using ? for sql injection safety
    cursor.execute("INSERT INTO `feature` VALUES(?,?,?,?,?,?)", inputValues)
connection.commit()

for feature in featureXML.getSimpleFeatureInfo():
    cursor.execute("DELETE FROM `feature` WHERE feature_id = ?", (str(featureXML['id']),))

Edit:

These are the tables that have foreign keys linking to features. They are not being filled  yet:

DROP TABLE IF EXISTS `convexhull`;
-- -----------------------------------------------------
-- Table `convexhull`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `convexhull` (
  `convexhull_id` INT PRIMARY KEY NOT NULL ,
  `mz` DOUBLE NOT NULL ,
  `rt` DOUBLE NOT NULL ,
  `feature_feature_id` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_convexhull_feature`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_convexhull_feature` ON `convexhull` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `position`;
-- -----------------------------------------------------
-- Table `position`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `position` (
  `position_id` INT PRIMARY KEY NOT NULL ,
  `dim0` INT NOT NULL ,
  `dim1` INT NOT NULL ,
  `feature_feature_id` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_position_feature1`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_position_feature1` ON `position` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `userParam_names`;
-- -----------------------------------------------------
-- Table `userParam_names`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `userParam_names` (
  `userParam_id` INT PRIMARY KEY NOT NULL ,
  `Name` VARCHAR(45) NOT NULL );

DROP TABLE IF EXISTS `feature_has_userParam_names`;
-- -----------------------------------------------------
-- Table IF EXISTS `feature_has_userParam_names`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature_has_userParam_names` (
  `feature_feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `userParam_names_userParam_id` INT NOT NULL ,
  CONSTRAINT `fk_feature_has_userParam_names_feature1`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_feature_has_userParam_names_userParam_names1`
    FOREIGN KEY (`userParam_names_userParam_id` )
    REFERENCES `userParam_names` (`userParam_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_feature_has_userParam_names_userParam_names1` ON `feature_has_userParam_names` (`userParam_names_userParam_id` ASC);
  CREATE INDEX `fk_feature_has_userParam_names_feature1` ON `feature_has_userParam_names` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `userParam_value`;
-- -----------------------------------------------------
-- Table IF EXISTS `userParam_value`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `userParam_value` (
  `iduserParam_value` INT PRIMARY KEY NOT NULL ,
  `userParam_name` VARCHAR(45) NOT NULL ,
  `value` VARCHAR(45) NOT NULL );

DROP TABLE IF EXISTS `feature_has_userParam_names_has_userParam_value`;
-- -----------------------------------------------------
-- Table `feature_has_userParam_names_has_userParam_value`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature_has_userParam_names_has_userParam_value` (
  `feature_has_userParam_names_feature_feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `feature_has_userParam_names_userParam_names_userParam_id` INT NOT NULL ,
  `userParam_value_iduserParam_value` INT NOT NULL ,
  CONSTRAINT `fk_feature_has_userParam_names_has_userParam_value_feature_ha1`
    FOREIGN KEY (`feature_has_userParam_names_feature_feature_id` , `feature_has_userParam_names_userParam_names_userParam_id` )
    REFERENCES `feature_has_userParam_names` (`feature_feature_id` , `userParam_names_userParam_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_feature_has_userParam_names_has_userParam_value_userParam_1`
    FOREIGN KEY (`userParam_value_iduserParam_value` )
    REFERENCES `userParam_value` (`iduserParam_value` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_feature_has_userParam_names_has_userParam_value_userParam_1` ON  `feature_has_userParam_names_has_userParam_value` (`userParam_value_iduserParam_value` ASC);
  CREATE INDEX `fk_feature_has_userParam_names_has_userParam_value_feature_ha1` ON  `feature_has_userParam_names_has_userParam_value` (`feature_has_userParam_names_feature_feature_id` ASC, `feature_has_userParam_names_userParam_names_userParam_id` ASC);

The delete statement does work when I do it from SQLite manager.

edit 2:

Full traceback:

Traceback (most recent call last):
  File "/homes/ndeklein/workspace/MS/Trunk/PyMS_dev/database/test.py", line 25, in <module>
    cursor.execute("DELETE FROM `feature` WHERE feature_id = 'f_13020522388175237334'")
pysqlite2.dbapi2.OperationalError: foreign key mismatch

Doing

DELETE FROM `feature` WHERE feature_id = 'f_13020522388175237334'

in SQLite Manager works.

Edit 3

Including all tables:

--------------------------------------------------------
-- pyMS database. Drops all tables before it makes them, should be changed before release
--------------------------------------------------------

DROP TABLE IF EXISTS `msrun`;
-- -----------------------------------------------------
-- Table `msrun`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `msrun` (
  `msrun_name` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `description` VARCHAR(500) NOT NULL );

DROP TABLE IF EXISTS `feature`;
-- -----------------------------------------------------
-- Table `feature`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature` (
  `feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `intensity` DOUBLE NOT NULL ,
  `overallquality` DOUBLE NOT NULL ,
  `charge` INT NOT NULL ,
  `content` VARCHAR(45) NOT NULL ,
  `msrun_msrun_name` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_feature_msrun1`
    FOREIGN KEY (`msrun_msrun_name` )
    REFERENCES `msrun` (`msrun_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE UNIQUE INDEX `id_UNIQUE` ON `feature` (`feature_id` ASC);
  CREATE INDEX `fk_feature_msrun1` ON `feature` (`msrun_msrun_name` ASC);

DROP TABLE IF EXISTS `convexhull`;
-- -----------------------------------------------------
-- Table `convexhull`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `convexhull` (
  `convexhull_id` INT PRIMARY KEY NOT NULL ,
  `mz` DOUBLE NOT NULL ,
  `rt` DOUBLE NOT NULL ,
  `feature_feature_id` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_convexhull_feature`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_convexhull_feature` ON `convexhull` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `position`;
-- -----------------------------------------------------
-- Table `position`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `position` (
  `position_id` INT PRIMARY KEY NOT NULL ,
  `dim0` INT NOT NULL ,
  `dim1` INT NOT NULL ,
  `feature_feature_id` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_position_feature1`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_position_feature1` ON `position` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `userParam_names`;
-- -----------------------------------------------------
-- Table `userParam_names`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `userParam_names` (
  `userParam_id` INT PRIMARY KEY NOT NULL ,
  `Name` VARCHAR(45) NOT NULL );

DROP TABLE IF EXISTS `feature_has_userParam_names`;
-- -----------------------------------------------------
-- Table IF EXISTS `feature_has_userParam_names`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature_has_userParam_names` (
  `feature_feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `userParam_names_userParam_id` INT NOT NULL ,
  CONSTRAINT `fk_feature_has_userParam_names_feature1`
    FOREIGN KEY (`feature_feature_id` )
    REFERENCES `feature` (`feature_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_feature_has_userParam_names_userParam_names1`
    FOREIGN KEY (`userParam_names_userParam_id` )
    REFERENCES `userParam_names` (`userParam_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_feature_has_userParam_names_userParam_names1` ON `feature_has_userParam_names` (`userParam_names_userParam_id` ASC);
  CREATE INDEX `fk_feature_has_userParam_names_feature1` ON `feature_has_userParam_names` (`feature_feature_id` ASC);

DROP TABLE IF EXISTS `userParam_value`;
-- -----------------------------------------------------
-- Table IF EXISTS `userParam_value`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `userParam_value` (
  `iduserParam_value` INT PRIMARY KEY NOT NULL ,
  `userParam_name` VARCHAR(45) NOT NULL ,
  `value` VARCHAR(45) NOT NULL );

DROP TABLE IF EXISTS `feature_has_userParam_names_has_userParam_value`;
-- -----------------------------------------------------
-- Table `feature_has_userParam_names_has_userParam_value`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `feature_has_userParam_names_has_userParam_value` (
  `feature_has_userParam_names_feature_feature_id` VARCHAR(40) PRIMARY KEY NOT NULL ,
  `feature_has_userParam_names_userParam_names_userParam_id` INT NOT NULL ,
  `userParam_value_iduserParam_value` INT NOT NULL ,
  CONSTRAINT `fk_feature_has_userParam_names_has_userParam_value_feature_ha1`
    FOREIGN KEY (`feature_has_userParam_names_feature_feature_id` , `feature_has_userParam_names_userParam_names_userParam_id` )
    REFERENCES `feature_has_userParam_names` (`feature_feature_id` , `userParam_names_userParam_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_feature_has_userParam_names_has_userParam_value_userParam_1`
    FOREIGN KEY (`userParam_value_iduserParam_value` )
    REFERENCES `userParam_value` (`iduserParam_value` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_feature_has_userParam_names_has_userParam_value_userParam_1` ON  `feature_has_userParam_names_has_userParam_value` (`userParam_value_iduserParam_value` ASC);
  CREATE INDEX `fk_feature_has_userParam_names_has_userParam_value_feature_ha1` ON  `feature_has_userParam_names_has_userParam_value` (`feature_has_userParam_names_feature_feature_id` ASC, `feature_has_userParam_names_userParam_names_userParam_id` ASC);

DROP TABLE IF EXISTS `precursor`;
-- -----------------------------------------------------
-- Table `precursor`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `precursor` (
  `precursor_id` INT PRIMARY KEY NOT NULL ,
  `ion_mz` DOUBLE NOT NULL ,
  `charge_state` INT NOT NULL ,
  `peak_intensity` DOUBLE NOT NULL );

DROP TABLE IF EXISTS `spectrum`;
-- -----------------------------------------------------
-- Table `spectrum`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `spectrum` (
  `spectrum_index` INT PRIMARY KEY NOT NULL ,
  `ms_level` INT NOT NULL ,
  `base_peak_mz` DOUBLE NOT NULL ,
  `base_peak_intensity` DOUBLE NOT NULL ,
  `total_ion_current` DOUBLE NOT NULL ,
  `lowest_observes_mz` DOUBLE NOT NULL ,
  `highest_observed_mz` DOUBLE NOT NULL ,
  `scan_start_time` DOUBLE NOT NULL ,
  `ion_injection_time` DOUBLE NOT NULL ,
  `msrun_msrun_name` VARCHAR(40) NOT NULL ,
  `precursor_precursor_id` INT NOT NULL ,
  CONSTRAINT `fk_spectrum_msrun1`
    FOREIGN KEY (`msrun_msrun_name` )
    REFERENCES `msrun` (`msrun_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_spectrum_precursor1`
    FOREIGN KEY (`precursor_precursor_id` )
    REFERENCES `precursor` (`precursor_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_spectrum_msrun1` ON `spectrum` (`msrun_msrun_name` ASC);
  CREATE INDEX `fk_spectrum_precursor1` ON `spectrum` (`precursor_precursor_id` ASC);

DROP TABLE IF EXISTS `spectrum_has_feature`;
-- -----------------------------------------------------
-- Table `spectrum_has_feature`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `spectrum_has_feature` (
  `spectrum_spectrum_index` INT PRIMARY KEY NOT NULL ,
  `spectrum_msrun_msrun_name` VARCHAR(40) NOT NULL ,
  `spectrum_precursor_precursor_id` INT NOT NULL ,
  `feature_feature_id` VARCHAR(40) NOT NULL ,
  `feature_msrun_msrun_name` VARCHAR(40) NOT NULL ,
  CONSTRAINT `fk_spectrum_has_feature_spectrum1`
    FOREIGN KEY (`spectrum_spectrum_index` , `spectrum_msrun_msrun_name` , `spectrum_precursor_precursor_id` )
    REFERENCES `spectrum` (`spectrum_index` , `msrun_msrun_msrun_name` , `precursor_precursor_id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_spectrum_has_feature_feature1`
    FOREIGN KEY (`feature_feature_id` , `feature_msrun_msrun_name` )
    REFERENCES `feature` (`feature_id` , `msrun_msrun_msrun_name` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);

  CREATE INDEX `fk_spectrum_has_feature_feature1` ON `spectrum_has_feature` (`feature_feature_id` ASC, `feature_msrun_msrun_name` ASC);
  CREATE INDEX `fk_spectrum_has_feature_spectrum1` ON `spectrum_has_feature` (`spectrum_spectrum_index` ASC, `spectrum_msrun_msrun_name` ASC, `spectrum_precursor_precursor_id` ASC);