问:
Export user data from Meteor to .CSV file
I'm creating a meteor app that has a user login system and a button. A user can press the button to add their username to a collection, until it is removed by a super-user.

I want to take note each time a user clicks the button, and download that information in a .csv file or a similar format. So, for example, say user A presses the button at time t1, user B presses it at time t2, user C presses it at t3, and then user A presses it again at time t4. I want to export a record of these interactions in a nice format. ***Note: the button clicks aren't stored in an array so the solution to this question (How to export JavaScript array info to csv (on client side)?) doesn't help me -- unless I'm misunderstanding something, which is totally possible!

I started working through this tutorial for exporting data from meteor apps (https://themeteorchef.com/tutorials/exporting-data-from-your-meteor-application) but it quickly became complicated, and I'm not sure how to keep track of the button clicks using this method.

This seems like a relatively simple task. Is there an easy work-around or common method that I'm missing out on? Thanks!

答:
Sorry for the delay, the holiday kept me away.

Since you're using Meteor, you have access to a great Mongo API (docs) that allows you to query and transform the data in whatever way you'd like. So simply query whatever you defined your Mongo collection as in Meteor (I'll use ButtonClicks as an example)

```<code>let buttonClicks = ButtonClicks.find({}).fetch(); // Finds all button clicks
</code>```

Then transform the data and use the Node fs (docs) package to write the transformed data to a .csv file.

```<code>buttonClicks = buttonClicks.map((click) => {
    // transform your json to csv format here.
    // I encourage you to write this yourself ;).
});

fs.writeFile('buttonClicks.csv', buttonClicks, (err) => {
    if (err) throw err;
    console.log('The file has been saved!');
});
</code>```

Body:
Sorry for the delay, the holiday kept me away.

Since you're using Meteor, you have access to a great Mongo API (docs) that allows you to query and transform the data in whatever way you'd like. So simply query whatever you defined your Mongo collection as in Meteor (I'll use ButtonClicks as an example)

let buttonClicks = ButtonClicks.find({}).fetch(); // Finds all button clicks

Then transform the data and use the Node fs (docs) package to write the transformed data to a .csv file.

buttonClicks = buttonClicks.map((click) => {
    // transform your json to csv format here.
    // I encourage you to write this yourself ;).
});

fs.writeFile('buttonClicks.csv', buttonClicks, (err) => {
    if (err) throw err;
    console.log('The file has been saved!');
});


来源: stackexchange

问:
My Android Buttons look a bit weird (screenshot attached)?
Screenshot

I want my buttons to be round, but they are oblate/oval (please take a look at the screenshot). Can anyone help? My code (There are 2 buttons at the bottom):

```<code><LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="?attr/actionBarSize"
    android:background="#ffffff"
    >

    <TextView
        android:id="@+id/tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:text="@string/package_size"
        tools:ignore="RtlSymmetry" />
    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:background="#e9eaea"/>
    <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/radio_group"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/radio_small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/small" />

        <RadioButton
            android:id="@+id/radio_medium"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/medium" />
        <RadioButton
            android:id="@+id/radio_large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/large" />
    </RadioGroup>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:weightSum="4"
        android:background="#e6e7e8"
        >
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_minus"/>

            <TextView android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0" />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_plus"/>
        </LinearLayout>

    </LinearLayout>
</LinearLayout>
</code>```

Do I need to change Layout? Or why is it happening?

答:
The plus and minus icons that you are using have a definite height and width. If you place them in a Layout smaller than their default size, they are bound to behave otherwise hence, specify their holder to be of size equal to or greater than the icon size.
In your case, just specify the height of the immediate Linear Layout tag of the buttons.</p>

ContentLicense: CC BY-SA 3.0

Body:
Screenshot

I want my buttons to be round, but they are oblate/oval (please take a look at the screenshot). Can anyone help? My code (There are 2 buttons at the bottom):

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingTop="?attr/actionBarSize"
    android:background="#ffffff"
    >

    <TextView
        android:id="@+id/tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:text="@string/package_size"
        tools:ignore="RtlSymmetry" />
    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:background="#e9eaea"/>
    <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/radio_group"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/radio_small"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/small" />

        <RadioButton
            android:id="@+id/radio_medium"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/medium" />
        <RadioButton
            android:id="@+id/radio_large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/large" />
    </RadioGroup>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:weightSum="4"
        android:background="#e6e7e8"
        >
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            >
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_minus"/>

            <TextView android:id="@+id/text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0" />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_plus"/>
        </LinearLayout>

    </LinearLayout>
</LinearLayout>

Do I need to change Layout? Or why is it happening?


问:
Custom font not working in React Native
I want to use a font from google fonts in my app. Here is the font.

I have placed the .ttf file in app/fonts.

package.json:

```<code>{
    "name": "xxx",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
    },
    "rnpm": {
        "assets": ["./app/fonts"]
    },
    "jest": {
        "preset": "react-native",
        "moduleNameMapper": {
            "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
            "\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
        }
    },
    "dependencies": {
        "flow-typed": "^2.0.0",
        "immutable": "^3.8.1",
        "react": "~15.4.1",
        "react-native": "0.42.0",
        "react-native-vector-icons": "^4.0.0",
        "react-redux": "^5.0.3",
        "redux": "^3.6.0",
        "redux-immutable": "^4.0.0",
        "redux-observable": "^0.14.1",
        "rxjs": "^5.2.0"
    },
    "devDependencies": {
        "babel-eslint": "^7.1.1",
        "babel-jest": "19.0.0",
        "babel-preset-react-native": "1.9.1",
        "eslint": "^3.17.0",
        "eslint-plugin-flowtype": "^2.30.3",
        "eslint-plugin-jsx": "^0.0.2",
        "eslint-plugin-react": "^6.10.0",
        "eslint-plugin-react-native": "^2.3.1",
        "flow-bin": "^0.42.0",
        "jest": "19.0.2",
        "jest-cli": "^19.0.2",
        "react-test-renderer": "~15.4.1",
        "redux-devtools": "^3.3.2",
        "remote-redux-devtools": "^0.5.7"
    }
}
</code>```

then ran react-native link.

Then use the font in my app:

```<code>import { View, Text } from 'react-native'
import React from 'react'
import Width from '../width/Width'
import Shape from '../shape/Shape'
import Height from '../height/Height'
import Thickness from '../thickness/Thickness'

export const Volcalc = () => (
  <View style={styles.container}>
    <Text style={styles.text}>SHAPE</Text>
    <Shape />
    <Text style={styles.text}>HEIGHT</Text>
    <Height />
    <Text style={styles.text}>WIDTH</Text>
    <Width />
    <Text style={styles.text}>THICKNESS</Text>
    <Thickness />
  </View>
)

const $mainColor = '#00d1b2'
const styles = {
  container: {
    flex: 1,
    padding: 20,
    backgroundColor: $mainColor
  },
  text: {
    textAlign: 'center',
    color: 'rgba(255, 255, 255, 0.9)',
    fontSize: 15,
    fontFamily: 'Orbitron'
  }
}
</code>```

In android it doesn't show the new font but has no error. In ios it has error:

Unrecognised font family "Orbitron"

What am I doing wrong?

How do I find out the EXACT value to place in fontFamily: 'xxx'?

答:
It doesn't look like you've linked correctly or your app just isn't loading the new resource.

Add

```<code>"rnpm": {
    "assets": ["./app/fonts"]
}
</code>```

to your package.json.

Then

```<code>rm -rf node_modules && npm install && react-native link
</code>```

If things go right, search inside android/app/src/main/assets/fonts/ for your custom font.
If you see it, you linked successfully.

Similarly for iOS, run XCode and expand Resource dropdown for your custom font.

Kill your emulator and re-try

```<code>react-native run-ios
</code>```

Title: Custom font not working in React Native

Body:
I want to use a font from google fonts in my app. Here is the font.

I have placed the .ttf file in app/fonts.

package.json:

{
    "name": "xxx",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
    },
    "rnpm": {
        "assets": ["./app/fonts"]
    },
    "jest": {
        "preset": "react-native",
        "moduleNameMapper": {
            "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
            "\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
        }
    },
    "dependencies": {
        "flow-typed": "^2.0.0",
        "immutable": "^3.8.1",
        "react": "~15.4.1",
        "react-native": "0.42.0",
        "react-native-vector-icons": "^4.0.0",
        "react-redux": "^5.0.3",
        "redux": "^3.6.0",
        "redux-immutable": "^4.0.0",
        "redux-observable": "^0.14.1",
        "rxjs": "^5.2.0"
    },
    "devDependencies": {
        "babel-eslint": "^7.1.1",
        "babel-jest": "19.0.0",
        "babel-preset-react-native": "1.9.1",
        "eslint": "^3.17.0",
        "eslint-plugin-flowtype": "^2.30.3",
        "eslint-plugin-jsx": "^0.0.2",
        "eslint-plugin-react": "^6.10.0",
        "eslint-plugin-react-native": "^2.3.1",
        "flow-bin": "^0.42.0",
        "jest": "19.0.2",
        "jest-cli": "^19.0.2",
        "react-test-renderer": "~15.4.1",
        "redux-devtools": "^3.3.2",
        "remote-redux-devtools": "^0.5.7"
    }
}

then ran react-native link.

Then use the font in my app:

import { View, Text } from 'react-native'
import React from 'react'
import Width from '../width/Width'
import Shape from '../shape/Shape'
import Height from '../height/Height'
import Thickness from '../thickness/Thickness'

export const Volcalc = () => (
  <View style={styles.container}>
    <Text style={styles.text}>SHAPE</Text>
    <Shape />
    <Text style={styles.text}>HEIGHT</Text>
    <Height />
    <Text style={styles.text}>WIDTH</Text>
    <Width />
    <Text style={styles.text}>THICKNESS</Text>
    <Thickness />
  </View>
)

const $mainColor = '#00d1b2'
const styles = {
  container: {
    flex: 1,
    padding: 20,
    backgroundColor: $mainColor
  },
  text: {
    textAlign: 'center',
    color: 'rgba(255, 255, 255, 0.9)',
    fontSize: 15,
    fontFamily: 'Orbitron'
  }
}

In android it doesn't show the new font but has no error. In ios it has error:

Unrecognised font family "Orbitron"

What am I doing wrong?

How do I find out the EXACT value to place in fontFamily: 'xxx'?

Body:
It doesn't look like you've linked correctly or your app just isn't loading the new resource.

Add

"rnpm": {
    "assets": ["./app/fonts"]
}

to your package.json.

Then

rm -rf node_modules && npm install && react-native link

If things go right, search inside android/app/src/main/assets/fonts/ for your custom font.
If you see it, you linked successfully.

Similarly for iOS, run XCode and expand Resource dropdown for your custom font.

Kill your emulator and re-try

react-native run-ios


问:
Unix sort of version numbers
I have a list of version numbers, let's say for instance that they are in a file versions.txt

```<code>1.2.100.4
1.2.3.4
10.1.2.3
9.1.2.3
</code>```

I wish to sort them so that they are sorted by version.  i.e:

```<code>1.2.3.4
1.2.100.4
9.1.2.3
10.1.2.3
</code>```

I have tried using various sort commands using the "k" parameters, but do not really understand it well enough to pull it off.  Any help would be appreciated.

答:
```<code>sort -n <versions.txt
</code>```

ContentLicense: CC BY-SA 2.5

Title: Unix sort of version numbers

Body:
I have a list of version numbers, let's say for instance that they are in a file versions.txt

1.2.100.4
1.2.3.4
10.1.2.3
9.1.2.3

I wish to sort them so that they are sorted by version.  i.e:

1.2.3.4
1.2.100.4
9.1.2.3
10.1.2.3

I have tried using various sort commands using the "k" parameters, but do not really understand it well enough to pull it off.  Any help would be appreciated.

Body: sort -n <versions.txt


问:
Use own username/password with git and bitbucket
I'm in a team of three; two are working locally, and I am working on the server.

My coworker set up the account, but gave me full privileges to the repository.

I set my username and email in git:

```<code>git config --global user.name "bozdoz"
git config --global user.email email@email.com
</code>```

and they are identical to my username and email on bitbucket.org.

But when I pull or push to the repository it indicates their username in the prompt:

```<code>Password for 'https://theirusername@bitbucket.org':
</code>```

I was able to get a prompt for my password after trying to pull by indicating the URL with my username:

```<code>git pull https://bozdoz@bitbucket.org/path/repo.git
</code>```

and it said up-to-date; and then when I pushed, it said no-fast-forward.

I read that I need to specify the branch, but I don't know how to do that in a push statement while I'm also specifying the repo URL:

```<code>git push https://bozdoz@bitbucket.org/path/repo.git
</code>```

I am able to pull and push if my co-worker is around and can put his password in.  But this is also listing him as the author of the push, and not me.

How can I pull and push to a repo branch as my own username?

答:
For myself private repo, i use

git@bitbucket.org:username/blog.git

replace

https://username@bitbucket.org/username/blog.git

Body:
I'm in a team of three; two are working locally, and I am working on the server.

My coworker set up the account, but gave me full privileges to the repository.

I set my username and email in git:

git config --global user.name "bozdoz"
git config --global user.email email@email.com

and they are identical to my username and email on bitbucket.org.

But when I pull or push to the repository it indicates their username in the prompt:

Password for 'https://theirusername@bitbucket.org':

I was able to get a prompt for my password after trying to pull by indicating the URL with my username:

git pull https://bozdoz@bitbucket.org/path/repo.git

and it said up-to-date; and then when I pushed, it said no-fast-forward.

I read that I need to specify the branch, but I don't know how to do that in a push statement while I'm also specifying the repo URL:

git push https://bozdoz@bitbucket.org/path/repo.git

I am able to pull and push if my co-worker is around and can put his password in.  But this is also listing him as the author of the push, and not me.

How can I pull and push to a repo branch as my own username?


问:
xytext details in Matplotlibs Annotate
With the following code I am plotting a candlestick graph and also make use of annotations. I have played arround until I found the right positions for the text, but I still don't understand what the figures xytext=(-15, -27) and xytext=(-17, 20) have to do with their current position.

It is very strange to me. could somebody please explain it to me? Many thanks in advance!

This is what my graph looks like and below is the code:

```<code>import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib.finance import candlestick_ohlc
from matplotlib import style
import pandas_datareader
import datetime as dt

style.use('classic')
start = dt.datetime(2017,1,1)
end = dt.datetime(2017,4,1)

def graph(stock):
    ax1 = plt.subplot2grid((1,1), (0,0))
    stock_data = pandas_datareader.DataReader(name=stock, data_source='google', start=start, end=end)
    stock_data.reset_index(inplace=True)
    stock_data['Date'] = stock_data['Date'].map(mdates.date2num)
    candlestick_ohlc(ax1, stock_data.values, width=0.5, colorup='g', colordown='r')

    ax1.annotate('Long',
                 xy=(stock_data['Date'][10], stock_data['Low'][10]),
                 xytext=(-15, -27),
                 textcoords='offset points',
                 arrowprops=dict(facecolor='grey', color='grey'))

    ax1.annotate('Short',
                 xy=(stock_data['Date'][28], stock_data['High'][28]),
                 xytext=(-17, 20),
                 textcoords='offset points',
                 arrowprops=dict(facecolor='grey', color='grey'))

    ax1.annotate('Long',
                 xy=(stock_data['Date'][42], stock_data['Low'][42]),
                 xytext=(-15, -27),
                 textcoords='offset points',
                 arrowprops=dict(facecolor='grey', color='grey'))

    ax1.annotate('Short',
                 xy=(stock_data['Date'][48], stock_data['High'][48]),
                 xytext=(-17, 20),
                 textcoords='offset points',
                 arrowprops=dict(facecolor='grey', color='grey'))

    plt.show()

graph('TSLA')
</code>```

答:
You chose to have the text coordinates in offset points. E.g. xytext=(-17, 20) places the text at 17 points to the left and 20 points to the top from the point which you annotate.

The coordinates may be more obvious when changing the horizontalalignment to "center" in the annotation. annotate( ... , ha="center").

You can then get the result by setting the x coordinate to 0.

```<code>ax1.annotate('Long', xy=(stock_data['Date'][10], stock_data['Low'][10]),
                 xytext=(0, -27),
                 textcoords='offset points', ha="center",
                 arrowprops=dict(facecolor='grey', color='grey'))
</code>```

Title: xytext details in Matplotlibs Annotate

Body:
With the following code I am plotting a candlestick graph and also make use of annotations. I have played arround until I found the right positions for the text, but I still don't understand what the figures xytext=(-15, -27) and xytext=(-17, 20) have to do with their current position.

It is very strange to me. could somebody please explain it to me? Many thanks in advance!

This is what my graph looks like and below is the code:

import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib.finance import candlestick_ohlc
from matplotlib import style
import pandas_datareader
import datetime as dt

style.use('classic')
start = dt.datetime(2017,1,1)
end = dt.datetime(2017,4,1)

def graph(stock):
    ax1 = plt.subplot2grid((1,1), (0,0))
    stock_data = pandas_datareader.DataReader(name=stock, data_source='google', start=start, end=end)
    stock_data.reset_index(inplace=True)
    stock_data['Date'] = stock_data['Date'].map(mdates.date2num)
    candlestick_ohlc(ax1, stock_data.values, width=0.5, colorup='g', colordown='r')

    ax1.annotate('Long',
                 xy=(stock_data['Date'][10], stock_data['Low'][10]),
                 xytext=(-15, -27),
                 textcoords='offset points',
                 arrowprops=dict(facecolor='grey', color='grey'))

    ax1.annotate('Short',
                 xy=(stock_data['Date'][28], stock_data['High'][28]),
                 xytext=(-17, 20),
                 textcoords='offset points',
                 arrowprops=dict(facecolor='grey', color='grey'))

    ax1.annotate('Long',
                 xy=(stock_data['Date'][42], stock_data['Low'][42]),
                 xytext=(-15, -27),
                 textcoords='offset points',
                 arrowprops=dict(facecolor='grey', color='grey'))

    ax1.annotate('Short',
                 xy=(stock_data['Date'][48], stock_data['High'][48]),
                 xytext=(-17, 20),
                 textcoords='offset points',
                 arrowprops=dict(facecolor='grey', color='grey'))

    plt.show()

graph('TSLA')

Body:
You chose to have the text coordinates in offset points. E.g. xytext=(-17, 20) places the text at 17 points to the left and 20 points to the top from the point which you annotate.

The coordinates may be more obvious when changing the horizontalalignment to "center" in the annotation. annotate( ... , ha="center").

You can then get the result by setting the x coordinate to 0.

ax1.annotate('Long', xy=(stock_data['Date'][10], stock_data['Low'][10]),
                 xytext=(0, -27),
                 textcoords='offset points', ha="center",
                 arrowprops=dict(facecolor='grey', color='grey'))


问:
sql query/oracle
I have a 2 tables Existing_tools and Recommendation_tool having 4 columns (Account, Activity, Tools_name, count) but last column gives me number of existing tools and number of recommended tools count in respective tables.

I want output (Account, Activity, Tools_name, existing_tools_count, recommendation_tools_count), group by account and activity
and all tools present in both the tables comes in output.

If tool name is not present in existing table then count will be 0 against existing_tools_count, same way if tool is not present in recommendation table count against recommendation_tools_count count will be 0.

And if tool is present in both the tables then given count will come accordingly.

Existing_TOOLS

```<code>Account Activity       tools_Name   Number of Existing_tool
x   Agile/Proj. Mgmt    JIRA             5
x   Agile/Proj. Mgmt    Collabnet        4
x   Build               ANT              3
x   Build               MAVEN            3
y   Agile/Proj. Mgmt    JIRA             5
y   Agile/Proj. Mgmt    Collabnet        4
y   Build               ANT              3
y   Build               MAVEN            3
</code>```

Recommendation_tool

```<code>Account    Activity    tools_Name    Number of recommendation_tool
x    Agile/Proj. Mgmt    JIRA         5
x    Agile/Proj. Mgmt    HP ALM       4
x    Build               MS build     3
y    Agile/Proj. Mgmt    JIRA         5
y    Agile/Proj. Mgmt    HP ALM       4
y    Build               MS build     3
</code>```

Required_TABLE

```<code>Account    Activity    tools_Name    Number of Existing_tool    Number of recommendation_tool
x    Agile/Proj. Mgmt    JIRA                5                         5
x    Agile/Proj. Mgmt    Collabnet           4                         0
x    Agile/Proj. Mgmt    HP ALM              0                         4
x    Build               ANT                 3                         0
x    Build               MAVEN               3                         0
x    Build               MS build            0                         3
y    Agile/Proj. Mgmt    JIRA                5                         5
y    Agile/Proj. Mgmt    Collabnet           4                         0
y    Agile/Proj. Mgmt    HP ALM              0                         4
y    Build               ANT                 3                         0
y    Build               MAVEN               3                         0
y    Build               MS build            0                         3
</code>```

答:
Seems like a full outer join and a few coalesces would work.

Coalesce() returns the first non-null value in a series.  so in the example coalesce(ET.Account, RT.Account) ET.Account value will return if not null; otherwise RT.Account will be returned even if null; thus one way or another we get the Account value or a NULL (but only if the account isn't populated in both tables.)

FULL OUTER JOIN will join two data sets together based on keys and return all records from either source matching on values in the 'on' when it can. thus combining records from both data sets where appropriate.

This does assume that the account, activity and tool name denote  unique record in each table (and that none of the values are null)

```<code>SELECT coalesce(ET.Account, RT.Account) as Account
     , coalesce(ET.Activity, RT.Activity) as Activity
     , coalesce(ET.Tools_name, RT.Tools_name) as Tools_name
     , coalesce(RT.Count,0) as Rec_tool_Count
     , coalesce(ET.Count,0) as Existing_tool_count
FROM Existing_tools ET
FULL OUTER JOIN Recomendation_Tool RT
  on ET.Account = RT.Account
 and ET.Activity = RT.Activity
 and ET.Tools_name = RT.Tools_Name
ORDER BY coalesce(ET.Account, RT.Account), coalesce(ET.Activity, RT.Activity)
</code>```

Not sure what you mean by group by account activity... maybe order by?  Group by is used with aggregation which there is none here...

or maybe you want to sum the counts in which case a group by again makes sense as perhaps you have multiple records in one or both of the tables for an account tool and activity.

```<code>SELECT coalesce(ET.Account, RT.Account) as Account
     , coalesce(ET.Activity, RT.Activity) as Activity
     , coalesce(ET.Tools_name, RT.Tools_name) as Tools_name
     , sum(coalesce(RT.Count,0)) as SUM_Rec_tool_Count
     , sum(coalesce(ET.Count,0)) as SUM_Existing_tool_count
FROM Existing_tools ET
FULL OUTER JOIN Recomendation_Tool RT
  on ET.Account = RT.Account
 and ET.Activity = RT.Activity
 and ET.Tools_name = RT.Tools_Name
GROUP BY coalesce(ET.Account, RT.Account) as Account
       , coalesce(ET.Activity, RT.Activity) as Activity
       , coalesce(ET.Tools_name, RT.Tools_name) as Tools_name
ORDER BY coalesce(ET.Account, RT.Account), coalesce(ET.Activity, RT.Activity)
</code>```

Title: sql query/oracle

Body:
I have a 2 tables Existing_tools and Recommendation_tool having 4 columns (Account, Activity, Tools_name, count) but last column gives me number of existing tools and number of recommended tools count in respective tables.

I want output (Account, Activity, Tools_name, existing_tools_count, recommendation_tools_count), group by account and activity
and all tools present in both the tables comes in output.

If tool name is not present in existing table then count will be 0 against existing_tools_count, same way if tool is not present in recommendation table count against recommendation_tools_count count will be 0.

And if tool is present in both the tables then given count will come accordingly.

Existing_TOOLS

Account Activity       tools_Name   Number of Existing_tool
x   Agile/Proj. Mgmt    JIRA             5
x   Agile/Proj. Mgmt    Collabnet        4
x   Build               ANT              3
x   Build               MAVEN            3
y   Agile/Proj. Mgmt    JIRA             5
y   Agile/Proj. Mgmt    Collabnet        4
y   Build               ANT              3
y   Build               MAVEN            3

Recommendation_tool

Account    Activity    tools_Name    Number of recommendation_tool
x    Agile/Proj. Mgmt    JIRA         5
x    Agile/Proj. Mgmt    HP ALM       4
x    Build               MS build     3
y    Agile/Proj. Mgmt    JIRA         5
y    Agile/Proj. Mgmt    HP ALM       4
y    Build               MS build     3

Required_TABLE

Account    Activity    tools_Name    Number of Existing_tool    Number of recommendation_tool
x    Agile/Proj. Mgmt    JIRA                5                         5
x    Agile/Proj. Mgmt    Collabnet           4                         0
x    Agile/Proj. Mgmt    HP ALM              0                         4
x    Build               ANT                 3                         0
x    Build               MAVEN               3                         0
x    Build               MS build            0                         3
y    Agile/Proj. Mgmt    JIRA                5                         5
y    Agile/Proj. Mgmt    Collabnet           4                         0
y    Agile/Proj. Mgmt    HP ALM              0                         4
y    Build               ANT                 3                         0
y    Build               MAVEN               3                         0
y    Build               MS build            0                         3

Body:
Seems like a full outer join and a few coalesces would work.

Coalesce() returns the first non-null value in a series.  so in the example coalesce(ET.Account, RT.Account) ET.Account value will return if not null; otherwise RT.Account will be returned even if null; thus one way or another we get the Account value or a NULL (but only if the account isn't populated in both tables.)

FULL OUTER JOIN will join two data sets together based on keys and return all records from either source matching on values in the 'on' when it can. thus combining records from both data sets where appropriate.

This does assume that the account, activity and tool name denote  unique record in each table (and that none of the values are null)

SELECT coalesce(ET.Account, RT.Account) as Account
     , coalesce(ET.Activity, RT.Activity) as Activity
     , coalesce(ET.Tools_name, RT.Tools_name) as Tools_name
     , coalesce(RT.Count,0) as Rec_tool_Count
     , coalesce(ET.Count,0) as Existing_tool_count
FROM Existing_tools ET
FULL OUTER JOIN Recomendation_Tool RT
  on ET.Account = RT.Account
 and ET.Activity = RT.Activity
 and ET.Tools_name = RT.Tools_Name
ORDER BY coalesce(ET.Account, RT.Account), coalesce(ET.Activity, RT.Activity)

Not sure what you mean by group by account activity... maybe order by?  Group by is used with aggregation which there is none here...

or maybe you want to sum the counts in which case a group by again makes sense as perhaps you have multiple records in one or both of the tables for an account tool and activity.

SELECT coalesce(ET.Account, RT.Account) as Account
     , coalesce(ET.Activity, RT.Activity) as Activity
     , coalesce(ET.Tools_name, RT.Tools_name) as Tools_name
     , sum(coalesce(RT.Count,0)) as SUM_Rec_tool_Count
     , sum(coalesce(ET.Count,0)) as SUM_Existing_tool_count
FROM Existing_tools ET
FULL OUTER JOIN Recomendation_Tool RT
  on ET.Account = RT.Account
 and ET.Activity = RT.Activity
 and ET.Tools_name = RT.Tools_Name
GROUP BY coalesce(ET.Account, RT.Account) as Account
       , coalesce(ET.Activity, RT.Activity) as Activity
       , coalesce(ET.Tools_name, RT.Tools_name) as Tools_name
ORDER BY coalesce(ET.Account, RT.Account), coalesce(ET.Activity, RT.Activity)


问:
seaborn : plotting graph from dataframe in loop not working as expected
I am trying to plot tsplot of seaborn from dataframe.
Here is the code I have

```<code>df = run_fully_connected_network(20, 200)
# print(df)
for feature in features:
    df_feature = df.loc[df['feature'] == feature]
#     print(df_feature)
    plt.figure()
    plt.title(feature)
#     plt.plot(figsize=(20,15))
    sns.tsplot(time="iteration", unit="feature", condition = "traits", value="count", data=df_feature)
</code>```

Here is how dataframe looks for each iteration (df_feature):

iteration 1:

```<code>      iteration    feature traits proportion  count
1             0  education      1        n/a      4
2             0  education      2        n/a      5
3             0  education      3        n/a      7
4             0  education      4        n/a      4
18            1  education      1        n/a      4
19            1  education      2        n/a      5
20            1  education      3        n/a      8
21            1  education      4        n/a      3
35            2  education      1        n/a      2
36            2  education      2        n/a      7
37            2  education      3        n/a      8
38            2  education      4        n/a      3
51            3  education      1        n/a      1
52            3  education      2        n/a      7
53            3  education      3        n/a      9
54            3  education      4        n/a      3
67            4  education      1        n/a      1
68            4  education      2        n/a      8
69            4  education      3        n/a      8
70            4  education      4        n/a      3
83            5  education      1        n/a      1
84            5  education      2        n/a      7
85            5  education      3        n/a      8
86            5  education      4        n/a      4
99            6  education      1        n/a      2
100           6  education      2        n/a      5
101           6  education      3        n/a      9
102           6  education      4        n/a      4
115           7  education      1        n/a      3
116           7  education      2        n/a      5
...         ...        ...    ...        ...    ...
1049        170  education      3        n/a     20
1053        171  education      3        n/a     20
1057        172  education      3        n/a     20
1061        173  education      3        n/a     20
1065        174  education      3        n/a     20
1069        175  education      3        n/a     20
1073        176  education      3        n/a     20
1077        177  education      3        n/a     20
1081        178  education      3        n/a     20
1085        179  education      3        n/a     20
1089        180  education      3        n/a     20
1093        181  education      3        n/a     20
1097        182  education      3        n/a     20
1101        183  education      3        n/a     20
1105        184  education      3        n/a     20
1109        185  education      3        n/a     20
1113        186  education      3        n/a     20
1117        187  education      3        n/a     20
1121        188  education      3        n/a     20
1125        189  education      3        n/a     20
1129        190  education      3        n/a     20
1133        191  education      3        n/a     20
1137        192  education      3        n/a     20
1141        193  education      3        n/a     20
1145        194  education      3        n/a     20
1149        195  education      3        n/a     20
1153        196  education      3        n/a     20
1157        197  education      3        n/a     20
1161        198  education      3        n/a     20
1165        199  education      3        n/a     20
</code>```

iteration 2:

```<code>      iteration   feature traits proportion  count
5             0  religion      1        n/a      5
6             0  religion      2        n/a      4
7             0  religion      3        n/a      6
8             0  religion      5        n/a      5
22            1  religion      1        n/a      5
23            1  religion      2        n/a      4
24            1  religion      3        n/a      7
25            1  religion      5        n/a      4
39            2  religion      1        n/a      5
40            2  religion      2        n/a      3
41            2  religion      3        n/a      8
42            2  religion      5        n/a      4
55            3  religion      1        n/a      7
56            3  religion      2        n/a      2
57            3  religion      3        n/a      8
58            3  religion      5        n/a      3
71            4  religion      1        n/a      7
72            4  religion      2        n/a      2
73            4  religion      3        n/a      8
74            4  religion      5        n/a      3
87            5  religion      1        n/a      5
88            5  religion      2        n/a      2
89            5  religion      3        n/a      8
90            5  religion      5        n/a      5
103           6  religion      1        n/a      5
104           6  religion      2        n/a      3
105           6  religion      3        n/a      7
106           6  religion      5        n/a      5
119           7  religion      1        n/a      4
120           7  religion      2        n/a      5
...         ...       ...    ...        ...    ...
1050        170  religion      3        n/a     20
1054        171  religion      3        n/a     20
1058        172  religion      3        n/a     20
1062        173  religion      3        n/a     20
1066        174  religion      3        n/a     20
1070        175  religion      3        n/a     20
1074        176  religion      3        n/a     20
1078        177  religion      3        n/a     20
1082        178  religion      3        n/a     20
1086        179  religion      3        n/a     20
1090        180  religion      3        n/a     20
1094        181  religion      3        n/a     20
1098        182  religion      3        n/a     20
1102        183  religion      3        n/a     20
1106        184  religion      3        n/a     20
1110        185  religion      3        n/a     20
1114        186  religion      3        n/a     20
1118        187  religion      3        n/a     20
1122        188  religion      3        n/a     20
1126        189  religion      3        n/a     20
1130        190  religion      3        n/a     20
1134        191  religion      3        n/a     20
1138        192  religion      3        n/a     20
1142        193  religion      3        n/a     20
1146        194  religion      3        n/a     20
1150        195  religion      3        n/a     20
1154        196  religion      3        n/a     20
1158        197  religion      3        n/a     20
1162        198  religion      3        n/a     20
1166        199  religion      3        n/a     20
</code>```

Iteration 3:

Similar dataframe

so basically there are 200 iterations. In x-axis I would expect range from 0 to 200. This is how the graph looks like at the moment

Why am I getting different range in x-axis. Each dataframe has value between 0-199. So the graph should have had x-axis value from 0-199. But here each graph has different range even though iteration value is same for each dataframe.

Also, every run I get different range in x-axis. For example, in second run for religion I get x-axis range from 0-200. Here is a sample

Is there some way I can control the range that can be shown in graph? Or am I doing something wrong?

答:
Since you already know "each dataframe has value between 0-199", try using plt.xlim(0, 200) after your iteration. That's one way you can control the range of x-axis.

Details are seaborn.tsplot() set xlim using the min() and max() of the last sets of data (based on data.groupby(condition, sort=False)), as you can see here. Specifically, x-axis ranges of your 4 plots are controlled by "traits 4 in education", "traits 5 in religion", "traits 4 in social status" and "traits 2 in religion", respectively. I'm not sure why it happened that way. You may raise an issue about it.

Body:
I am trying to plot tsplot of seaborn from dataframe.
Here is the code I have

df = run_fully_connected_network(20, 200)
# print(df)
for feature in features:
    df_feature = df.loc[df['feature'] == feature]
#     print(df_feature)
    plt.figure()
    plt.title(feature)
#     plt.plot(figsize=(20,15))
    sns.tsplot(time="iteration", unit="feature", condition = "traits", value="count", data=df_feature)

Here is how dataframe looks for each iteration (df_feature):

iteration 1:

      iteration    feature traits proportion  count
1             0  education      1        n/a      4
2             0  education      2        n/a      5
3             0  education      3        n/a      7
4             0  education      4        n/a      4
18            1  education      1        n/a      4
19            1  education      2        n/a      5
20            1  education      3        n/a      8
21            1  education      4        n/a      3
35            2  education      1        n/a      2
36            2  education      2        n/a      7
37            2  education      3        n/a      8
38            2  education      4        n/a      3
51            3  education      1        n/a      1
52            3  education      2        n/a      7
53            3  education      3        n/a      9
54            3  education      4        n/a      3
67            4  education      1        n/a      1
68            4  education      2        n/a      8
69            4  education      3        n/a      8
70            4  education      4        n/a      3
83            5  education      1        n/a      1
84            5  education      2        n/a      7
85            5  education      3        n/a      8
86            5  education      4        n/a      4
99            6  education      1        n/a      2
100           6  education      2        n/a      5
101           6  education      3        n/a      9
102           6  education      4        n/a      4
115           7  education      1        n/a      3
116           7  education      2        n/a      5
...         ...        ...    ...        ...    ...
1049        170  education      3        n/a     20
1053        171  education      3        n/a     20
1057        172  education      3        n/a     20
1061        173  education      3        n/a     20
1065        174  education      3        n/a     20
1069        175  education      3        n/a     20
1073        176  education      3        n/a     20
1077        177  education      3        n/a     20
1081        178  education      3        n/a     20
1085        179  education      3        n/a     20
1089        180  education      3        n/a     20
1093        181  education      3        n/a     20
1097        182  education      3        n/a     20
1101        183  education      3        n/a     20
1105        184  education      3        n/a     20
1109        185  education      3        n/a     20
1113        186  education      3        n/a     20
1117        187  education      3        n/a     20
1121        188  education      3        n/a     20
1125        189  education      3        n/a     20
1129        190  education      3        n/a     20
1133        191  education      3        n/a     20
1137        192  education      3        n/a     20
1141        193  education      3        n/a     20
1145        194  education      3        n/a     20
1149        195  education      3        n/a     20
1153        196  education      3        n/a     20
1157        197  education      3        n/a     20
1161        198  education      3        n/a     20
1165        199  education      3        n/a     20

iteration 2:

      iteration   feature traits proportion  count
5             0  religion      1        n/a      5
6             0  religion      2        n/a      4
7             0  religion      3        n/a      6
8             0  religion      5        n/a      5
22            1  religion      1        n/a      5
23            1  religion      2        n/a      4
24            1  religion      3        n/a      7
25            1  religion      5        n/a      4
39            2  religion      1        n/a      5
40            2  religion      2        n/a      3
41            2  religion      3        n/a      8
42            2  religion      5        n/a      4
55            3  religion      1        n/a      7
56            3  religion      2        n/a      2
57            3  religion      3        n/a      8
58            3  religion      5        n/a      3
71            4  religion      1        n/a      7
72            4  religion      2        n/a      2
73            4  religion      3        n/a      8
74            4  religion      5        n/a      3
87            5  religion      1        n/a      5
88            5  religion      2        n/a      2
89            5  religion      3        n/a      8
90            5  religion      5        n/a      5
103           6  religion      1        n/a      5
104           6  religion      2        n/a      3
105           6  religion      3        n/a      7
106           6  religion      5        n/a      5
119           7  religion      1        n/a      4
120           7  religion      2        n/a      5
...         ...       ...    ...        ...    ...
1050        170  religion      3        n/a     20
1054        171  religion      3        n/a     20
1058        172  religion      3        n/a     20
1062        173  religion      3        n/a     20
1066        174  religion      3        n/a     20
1070        175  religion      3        n/a     20
1074        176  religion      3        n/a     20
1078        177  religion      3        n/a     20
1082        178  religion      3        n/a     20
1086        179  religion      3        n/a     20
1090        180  religion      3        n/a     20
1094        181  religion      3        n/a     20
1098        182  religion      3        n/a     20
1102        183  religion      3        n/a     20
1106        184  religion      3        n/a     20
1110        185  religion      3        n/a     20
1114        186  religion      3        n/a     20
1118        187  religion      3        n/a     20
1122        188  religion      3        n/a     20
1126        189  religion      3        n/a     20
1130        190  religion      3        n/a     20
1134        191  religion      3        n/a     20
1138        192  religion      3        n/a     20
1142        193  religion      3        n/a     20
1146        194  religion      3        n/a     20
1150        195  religion      3        n/a     20
1154        196  religion      3        n/a     20
1158        197  religion      3        n/a     20
1162        198  religion      3        n/a     20
1166        199  religion      3        n/a     20

Iteration 3:

Similar dataframe

so basically there are 200 iterations. In x-axis I would expect range from 0 to 200. This is how the graph looks like at the moment

Why am I getting different range in x-axis. Each dataframe has value between 0-199. So the graph should have had x-axis value from 0-199. But here each graph has different range even though iteration value is same for each dataframe.

Also, every run I get different range in x-axis. For example, in second run for religion I get x-axis range from 0-200. Here is a sample

Is there some way I can control the range that can be shown in graph? Or am I doing something wrong?


问:
Problem when assigning a pointer to an enum variable in C
I am getting a warning of "assigment from incompatible pointer type".  I don't understand why this warning is happening. I don't know what else to declare "the_go_status" variable to other than an integer. (Note: this is not all the code, but just a simplified version I posted to illustrate the problem.)

The warning occurs on the last line of the example I included below.

```<code>//In a header file
enum error_type
{
    ERR_1 = 0,
    ERR_2 = 1,
    ERR_3 = 2,
    ERR_4 = 4,
};

//In a header file
struct error_struct
{
   int value;
   enum error_type *status;
};

//In a C file
int the_go_status;

the_go_status = ERR_1;

//Have the error_struct "status" point to the address of "the_go_status"
error_struct.status = &the_go_status;    //WARNING HERE!
</code>```

答:
The "the_go_status" should be typed "enum error_type".
You could typedef the enum</p>

Body:
I am getting a warning of "assigment from incompatible pointer type".  I don't understand why this warning is happening. I don't know what else to declare "the_go_status" variable to other than an integer. (Note: this is not all the code, but just a simplified version I posted to illustrate the problem.)

The warning occurs on the last line of the example I included below.

//In a header file
enum error_type
{
    ERR_1 = 0,
    ERR_2 = 1,
    ERR_3 = 2,
    ERR_4 = 4,
};

//In a header file
struct error_struct
{
   int value;
   enum error_type *status;
};

//In a C file
int the_go_status;

the_go_status = ERR_1;

//Have the error_struct "status" point to the address of "the_go_status"
error_struct.status = &the_go_status;    //WARNING HERE!


问:
Getting thread 1 signal SIGQUIT
I am getting thread 1: signal SIGQUIT when running my app. But when I click on continue execution, app is resuming and completing the task. Not sure why I am getting this

```<code>NSArray *keyNamesForKAV = [[NSArray alloc]initWithObjects:@"aKAV",@"bKAV",@"cKAV",@"dKAV",@"eKAV",@"fKAV",@"gKAV",@"hKAV",@"iKAV",@"jKAV",@"kKAV",@"lKAV",@"mKAV",@"nKAV",@"oKAV",@"pKAV",@"qKAV",@"rKAV",@"sKAV",@"tKAV",@"uKAV",@"vKAV",@"wKAV",@"xKAV",@"yKAV",@"zKAV", nil];

NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
KAVTrie *kavTree = [defaults rm_customObjectForKey:@"zKAV"];
NSMutableArray *KAVArray = [[NSMutableArray alloc]init];
if (!kavTree){
    for (int i = 0 ; i < 26; i++){
        KAVTrie *trie = [[KAVTrie alloc]init];
        KAVTrie *trieLoad = [[KAVTrie alloc]init];
        NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%c",[[keyNamesForKAV objectAtIndex:i] characterAtIndex:0]]  ofType:@"plist"];
        NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:path];
        NSArray *array = [tempDict allKeys];

        trie = [trieLoad storeTrieInArray:array];
        [KAVArray addObject:trie];
    }
    NSLog(@"KAV objects created");

    for (int i = 0 ; i < 26; i++){
        [defaults rm_setCustomObject:[KAVArray objectAtIndex:i] forKey:[keyNamesForKAV objectAtIndex:i]];
        [defaults synchronize];
    }

    NSLog(@"KAV objects loaded in user defaults");

}
</code>```

I am getting error in the second for loop

答: I figured out. There is an issue with my KAV class file</p>

Title: Getting thread 1 signal SIGQUIT

Body:
I am getting thread 1: signal SIGQUIT when running my app. But when I click on continue execution, app is resuming and completing the task. Not sure why I am getting this

NSArray *keyNamesForKAV = [[NSArray alloc]initWithObjects:@"aKAV",@"bKAV",@"cKAV",@"dKAV",@"eKAV",@"fKAV",@"gKAV",@"hKAV",@"iKAV",@"jKAV",@"kKAV",@"lKAV",@"mKAV",@"nKAV",@"oKAV",@"pKAV",@"qKAV",@"rKAV",@"sKAV",@"tKAV",@"uKAV",@"vKAV",@"wKAV",@"xKAV",@"yKAV",@"zKAV", nil];

NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
KAVTrie *kavTree = [defaults rm_customObjectForKey:@"zKAV"];
NSMutableArray *KAVArray = [[NSMutableArray alloc]init];
if (!kavTree){
    for (int i = 0 ; i < 26; i++){
        KAVTrie *trie = [[KAVTrie alloc]init];
        KAVTrie *trieLoad = [[KAVTrie alloc]init];
        NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%c",[[keyNamesForKAV objectAtIndex:i] characterAtIndex:0]]  ofType:@"plist"];
        NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:path];
        NSArray *array = [tempDict allKeys];

        trie = [trieLoad storeTrieInArray:array];
        [KAVArray addObject:trie];
    }
    NSLog(@"KAV objects created");

    for (int i = 0 ; i < 26; i++){
        [defaults rm_setCustomObject:[KAVArray objectAtIndex:i] forKey:[keyNamesForKAV objectAtIndex:i]];
        [defaults synchronize];
    }

    NSLog(@"KAV objects loaded in user defaults");

}

I am getting error in the second for loop


问:
object is not a function or function pointer
I am getting the following compilation error:

prog.c:13:5: error: called object is not a function or function pointer
    a=250(n-1)+192;

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

int main(){
    long long n,a;
    int t;

    scanf("%d",&t);
    while(t--){
        scanf("%lld",&n);
        a=250(n-1)+192;
        printf("%lld\n",a);
    }
}
</code>```

答:
You can't put a numeric constant right next to parenthesis like that.  This does not denote multiplication but a function call with 250 as the name of the function.

Use the binary * operator for multiplication.

```<code>a=250*(n-1)+192;
</code>```

Body:
I am getting the following compilation error:

prog.c:13:5: error: called object is not a function or function pointer
    a=250(n-1)+192;

#include <stdio.h>

int main(){
    long long n,a;
    int t;

    scanf("%d",&t);
    while(t--){
        scanf("%lld",&n);
        a=250(n-1)+192;
        printf("%lld\n",a);
    }
}

Body:
You can't put a numeric constant right next to parenthesis like that.  This does not denote multiplication but a function call with 250 as the name of the function.

Use the binary * operator for multiplication.

a=250*(n-1)+192;


问:
hide UIButtons when UITableView is empty
```<code>  func numberOfSections(in tableView: UITableView) -> Int {
        if carts.count > 0 {
            self.tableView.backgroundView = nil
            self.tableView.separatorStyle = .singleLine
            return 1

        }

        let rect = CGRect(x: 0,
                          y: 0,
                          width: self.tableView.bounds.size.width,
                          height: self.tableView.bounds.size.height)
        let noDataLabel: UILabel = UILabel(frame: rect)

        noDataLabel.text = "nothing, the table is empty"
        noDataLabel.textColor = UIColor.white
        noDataLabel.textAlignment = NSTextAlignment.center
        self.tableView.backgroundView = noDataLabel
        self.tableView.separatorStyle = .none
      self.total.isHidden = true
       self.proceedbtn.isHidden = true
        self.totalLab.isHidden = true

        return 1
    }
</code>```

the code above will hide the objects when the tableView is empty. However, when I add items in it ( it's supposed to be a cart) the total proceedbtn and totalLab are still hidden !!

Is there a way to reload the table and check if it's empty ?

Note :

My cells are slidable and I can delete the cell by sliding.

```<code>func deleteMail(_ path:IndexPath) {
    guard carts.count > path.row else {
        print("Index out of range")
        return
    }

    let entry = carts[path.row]
    deletItem(id: entry.meal_id)// call api to delete items
    carts.remove(at: (path as NSIndexPath).row);
    tableView.deleteRows(at: [path], with: .left);
    print("delete")

}
</code>```

UPDATE

```<code>override func viewDidLoad() {
    super.viewDidLoad()

    if carts.isEmpty == true {

        proceedbtn.isHidden = true
    } else {
        if carts.isEmpty == false {
            if proceedbtn.isHidden == true {

            proceedbtn.isHidden = false
        }
    }
    }
</code>```

get data :

```<code>func getData () {

    Alamofire.request(url!, method: .post, parameters: param,encoding: URLEncoding.default, headers: headers).responseJSON { response in
        if let value: AnyObject = response.result.value as AnyObject? {
       // get data

                 self.price = subJson["price"].stringValue
                 self.qty = subJson["qty"].stringValue
                 let id = subJson["id"].stringValue

              self.id = id
              self.name = subJson["meal"]["name"].stringValue

                let info = Cart(meal_id: self.id, qty: self.qty, meal_name: self.name, price: self.price)

                self.carts.append(info)
          }

        }
        self.tableView.reloadData()

    }

}
</code>```

答:
Sounds like you want something like a

```<code>func cartsDidUpdate() {
    let cartIsEmpty = carts.isEmpty
    total.isHidden = cartIsEmpty
    proceedbtn.isHidden = cartIsEmpty
    totalLab.isHidden = cartIsEmpty
    // Also any other UI-style logic based on cart being empty
}
</code>```

which you could call where you have print("delete") and could also call from wherever you add new carts.

Body:
  func numberOfSections(in tableView: UITableView) -> Int {
        if carts.count > 0 {
            self.tableView.backgroundView = nil
            self.tableView.separatorStyle = .singleLine
            return 1

        }

        let rect = CGRect(x: 0,
                          y: 0,
                          width: self.tableView.bounds.size.width,
                          height: self.tableView.bounds.size.height)
        let noDataLabel: UILabel = UILabel(frame: rect)

        noDataLabel.text = "nothing, the table is empty"
        noDataLabel.textColor = UIColor.white
        noDataLabel.textAlignment = NSTextAlignment.center
        self.tableView.backgroundView = noDataLabel
        self.tableView.separatorStyle = .none
      self.total.isHidden = true
       self.proceedbtn.isHidden = true
        self.totalLab.isHidden = true

        return 1
    }

the code above will hide the objects when the tableView is empty. However, when I add items in it ( it's supposed to be a cart) the total proceedbtn and totalLab are still hidden !!

Is there a way to reload the table and check if it's empty ?

Note :

My cells are slidable and I can delete the cell by sliding.

func deleteMail(_ path:IndexPath) {
    guard carts.count > path.row else {
        print("Index out of range")
        return
    }

    let entry = carts[path.row]
    deletItem(id: entry.meal_id)// call api to delete items
    carts.remove(at: (path as NSIndexPath).row);
    tableView.deleteRows(at: [path], with: .left);
    print("delete")

}

UPDATE

override func viewDidLoad() {
    super.viewDidLoad()

    if carts.isEmpty == true {

        proceedbtn.isHidden = true
    } else {
        if carts.isEmpty == false {
            if proceedbtn.isHidden == true {

            proceedbtn.isHidden = false
        }
    }
    }

get data :

func getData () {

    Alamofire.request(url!, method: .post, parameters: param,encoding: URLEncoding.default, headers: headers).responseJSON { response in
        if let value: AnyObject = response.result.value as AnyObject? {
       // get data

                 self.price = subJson["price"].stringValue
                 self.qty = subJson["qty"].stringValue
                 let id = subJson["id"].stringValue

              self.id = id
              self.name = subJson["meal"]["name"].stringValue

                let info = Cart(meal_id: self.id, qty: self.qty, meal_name: self.name, price: self.price)

                self.carts.append(info)
          }

        }
        self.tableView.reloadData()

    }

}

Body:
Sounds like you want something like a

func cartsDidUpdate() {
    let cartIsEmpty = carts.isEmpty
    total.isHidden = cartIsEmpty
    proceedbtn.isHidden = cartIsEmpty
    totalLab.isHidden = cartIsEmpty
    // Also any other UI-style logic based on cart being empty
}

which you could call where you have print("delete") and could also call from wherever you add new carts.


问:
Annotations testing issue
Testing When I provide @dataprovider class inside @test, it is throwing 'cannot be resolved into a type' error. Anybody knows how to resolve this?

答:
Data provider class is in different package. So that, it should be imported before using it. Please add import statement before using it.</p>

```<code>import DataProvider.Dp_Mercury;
</code>```

Title: Annotations testing issue

Body:
Data provider class is in different package. So that, it should be imported before using it. Please add import statement before using it.

import DataProvider.Dp_Mercury;


问:
How to align the content iniside the unordered list displayed using angular expression?
I am trying to align the the unordered list elements, but I cannot figure out how. So inside the list, I have 3 elements being displayed - key, value, and + symbol. Currently the elements are not aligned. But this is how I would like to display the content inside the boxes. .

This is how it looks

Also, if the amount of content increases, then it overflows the box. I would want to know how to properly style my elements to be aligned like in the pic.

Here is the plnkr

```<code><div ng-controller="stockCtrl">
    <section class="pickstocks">
        <label class="basiclabel">Pick Stocks</label>
        <div class="infoone">
            <p>Showing matching stocks</p>
            <button>Apply Filters</button>
        </div>
        <div class="stockpage">
            <ul id="nav">
                <li ng-repeat="(key,value) in stocks | objLimitTo:8">
                    {{key +"    "+ value + "  " + "+"}}
                </li>
            </ul>
        </div>
    </section>

    <section class="pickstocks">
        <label class="basiclabel">Manage Portfolio</label>
        <div>
            <table>
                <tr>
                <th>STOCK</th>
                <th>PRICE</th>
                <th>SHARES</th>
                <th>WEIGHT</th>
                </tr>
            </table>
        </div>
    </section>
</div>
</code>```

答:
You need to fix the width of either components like complete box or key or box height. Because if you want key width to be fixed, for large key values height of box may vary. Following are classes you need to add to span of key, value & '+' sign

```<code>.key-value {
  width: 90%;
  display: inline-block;
  word-wrap: break-word;
}

.plus {
  display: inline-block;
}

 <li ng-repeat="(key,value) in stocks | objLimitTo:8" >
 <span class="key-value"> {{key +"    "+ value}} </span>
 <span class="plus">+</span>
 </li>
</code>```

Here's working plunk example https://plnkr.co/edit/plS1vxqgpqJniAUNeTK5?p=preview
If you don't want height of box to change even for large key value then make

#nav li { width: auto }

Body:
I am trying to align the the unordered list elements, but I cannot figure out how. So inside the list, I have 3 elements being displayed - key, value, and + symbol. Currently the elements are not aligned. But this is how I would like to display the content inside the boxes. .

This is how it looks

Also, if the amount of content increases, then it overflows the box. I would want to know how to properly style my elements to be aligned like in the pic.

Here is the plnkr

        Pick Stocks

Showing matching stocks

            <button>Apply Filters</button>

                    {{key +"    "+ value + "  " + "+"}}

        Manage Portfolio

                STOCK
                PRICE
                SHARES
                WEIGHT

Body:
You need to fix the width of either components like complete box or key or box height. Because if you want key width to be fixed, for large key values height of box may vary. Following are classes you need to add to span of key, value & '+' sign

.key-value {
  width: 90%;
  display: inline-block;
  word-wrap: break-word;
}

.plus {
  display: inline-block;
}

 <li ng-repeat="(key,value) in stocks | objLimitTo:8" >
 <span class="key-value"> {{key +"&nbsp;&nbsp;&nbsp;&nbsp;"+ value}} </span>
 <span class="plus">+</span>
 </li>

Here's working plunk example https://plnkr.co/edit/plS1vxqgpqJniAUNeTK5?p=preview
If you don't want height of box to change even for large key value then make

#nav li { width: auto }


问:
Div not showing on hover?
So, I'm trying to make this so when I hover over the image, the div appears. Unfortunately, I am not able to get it to do so, and I'm at a loss as to why it's not working.

Here is my code:

.summary:hover {
  opacity: .6;
  -moz-transition: all .1s ease-in-out;
  -o-transition: all .1s ease-in-out;
  -webkit-transition: all .1s ease-in-out;
  transition: all .1s ease-in-out;
}

.summaryOverlay {
  position: absolute;
  margin-left: 5%;
  margin-top: 3%;
  height: 200px;
  width: 280px;
  z-index: 2;
  background-color: #E7DFDD;
  color: #0E0B16;
  font-family: Verdana;
  font-size: 15px;
  opacity: .9;
  -moz-transition: all .1s ease-in-out;
  -o-transition: all .1s ease-in-out;
  -webkit-transition: all .1s ease-in-out;
  transition: all .1s ease-in-out;
  text-align: center;
  display: none;
}

.summary:hover .summaryOverlay {
  display: block;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="leftAlign" id="lastWish">
  <img class="summary" alt="the last wish" src="lastWish.jpg" style="width: inherit; height: inherit;" />
</div>
<div class="summaryOverlay">
  Geralt is a witcher.
  <br><br>  Yet he is no ordinary killer-for-hire.
  <br><br> His sole purpose: to destroy the monsters that plague the world.
  <br><br> But not everything monstrous-looking is evil and not everything fair is good. . . and in every fairy tale there is a grain of truth.
</div></code>```

答:
Your CSS is not asking the browser to display the div on hovering over the image as you intended. Rather, it is asking the browser to display a child of .summary which has a class summaryOverlay. img can't ever have a child element, can it? Even if it could, .summaryOverlay is not its child. So, it won't work as you intended. Try this:

#lastWish:hover + .summaryOverlay{
  display:block;
}
```

Barring any CSS specificity issues, it should give you what want. Let me know how it goes.

Title: Div not showing on hover?

Body:
So, I'm trying to make this so when I hover over the image, the div appears. Unfortunately, I am not able to get it to do so, and I'm at a loss as to why it's not working.

Here is my code:

.summary:hover {
  opacity: .6;
  -moz-transition: all .1s ease-in-out;
  -o-transition: all .1s ease-in-out;
  -webkit-transition: all .1s ease-in-out;
  transition: all .1s ease-in-out;
}

.summaryOverlay {
  position: absolute;
  margin-left: 5%;
  margin-top: 3%;
  height: 200px;
  width: 280px;
  z-index: 2;
  background-color: #E7DFDD;
  color: #0E0B16;
  font-family: Verdana;
  font-size: 15px;
  opacity: .9;
  -moz-transition: all .1s ease-in-out;
  -o-transition: all .1s ease-in-out;
  -webkit-transition: all .1s ease-in-out;
  transition: all .1s ease-in-out;
  text-align: center;
  display: none;
}

.summary:hover .summaryOverlay {
  display: block;
}

  Geralt is a witcher.

  Yet he is no ordinary killer-for-hire.

 His sole purpose: to destroy the monsters that plague the world.

 But not everything monstrous-looking is evil and not everything fair is good. . . and in every fairy tale there is a grain of truth.

Body:
Your CSS is not asking the browser to display the div on hovering over the image as you intended. Rather, it is asking the browser to display a child of .summary which has a class summaryOverlay. img can't ever have a child element, can it? Even if it could, .summaryOverlay is not its child. So, it won't work as you intended. Try this:

#lastWish:hover + .summaryOverlay{
  display:block;
}

Barring any CSS specificity issues, it should give you what want. Let me know how it goes.

ContentLicense: CC BY-SA 4.0


问:
How do I write this AND/OR statement in SQL?
I have 2 fields: qty_released and qty_complete. I need to exclude rows where the qty_released = 1 and qty_complete = 0 at the same time. I can't do this:

```<code>--rest of code

and j.qty_released != 1
and j.qty_complete != 0

--rest of code
</code>```

...because there might be valid times when j.qty_complete = 0 while j.qty_released > 1. Similar situation for j.qty_released = 1. How should I write this? I need the query to consider both of these at the same time when filtering through a particular row.

答:
Try this:

```<code>where not (qty_released = 1 and qty_complete = 0)
</code>```

Or logical equivalent, but harder to read IMHO:

```<code>where (qty_released != 1 or qty_complete != 0)
</code>```

Body:
I have 2 fields: qty_released and qty_complete. I need to exclude rows where the qty_released = 1 and qty_complete = 0 at the same time. I can't do this:

--rest of code

and j.qty_released != 1
and j.qty_complete != 0

--rest of code

...because there might be valid times when j.qty_complete = 0 while j.qty_released > 1. Similar situation for j.qty_released = 1. How should I write this? I need the query to consider both of these at the same time when filtering through a particular row.

Body:
Try this:

where not (qty_released = 1 and qty_complete = 0)

Or logical equivalent, but harder to read IMHO:

where (qty_released != 1 or qty_complete != 0)


问:
Animated transform only for parent
Is there any way to set transform for parent element, but not for child element? I tried set reverse values of transform to child element. It's working, but nested animation doesn't run linearly, even if there is transition: all 1s linear;. Here is example.

.container, .title {
  transition: all 1s linear;
}

.image {
  background-image: url(https://www.w3schools.com/css/trolltunga.jpg);
  height: 300px;
  width: 800px;
}

.container {
  transform: scale(0.1); // 0.1× size of parent
}

.title {
  text-align: center;
  padding-top: 1rem;
  transform: scale(10); // 10× size of child
}

.container:hover {
  transform: scale(0.5); // 0.5× size of parent on hover
}

.container:hover .title {
  transform: scale(2); // 2× size of child on hover
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="container">
   <div class="image">

   </div>
   <h1 class="title">Title</h1>
</div></code>```

答:
Since transform scale is multiplicative, 2 transform scales do not compensate during the transition.

Another transform that looks like scale, and that is linear is translateZ, when there is a perspective applied. Move the object 9 times the perspective, and the apparent size will be 1/10th.

See you snippet, with 2 opposite translateZ applied:

body {
    perspective: 100px;
}
.container, .title {
  transition: all 1s linear;
}
.image {
  background-image: url(https://www.w3schools.com/css/trolltunga.jpg);
  height: 300px;
  width: 800px;
}
.container {
  transform: translateZ(-900px);
  transform-origin: center bottom;
  transform-style: preserve-3d;
}
.container:hover {
  transform: translateZ(-100px);
}

.title {
  text-align: center;
  padding-top: 1rem;
  transform: translateZ(900px);
  transform-style: preserve-3d;
}

.container:hover .title {
  transform: translateZ(100px);
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="container">
   <div class="image"></div>
   <h1 class="title">Title</h1>
</div></code>```

Title: Animated transform only for parent

Body:
Is there any way to set transform for parent element, but not for child element? I tried set reverse values of transform to child element. It's working, but nested animation doesn't run linearly, even if there is transition: all 1s linear;. Here is example.

.container, .title {
  transition: all 1s linear;
}

.image {
  background-image: url(https://www.w3schools.com/css/trolltunga.jpg);
  height: 300px;
  width: 800px;
}

.container {
  transform: scale(0.1); // 0.1× size of parent
}

.title {
  text-align: center;
  padding-top: 1rem;
  transform: scale(10); // 10× size of child
}

.container:hover {
  transform: scale(0.5); // 0.5× size of parent on hover
}

.container:hover .title {
  transform: scale(2); // 2× size of child on hover
}

Title

Body:
Since transform scale is multiplicative, 2 transform scales do not compensate during the transition.

Another transform that looks like scale, and that is linear is translateZ, when there is a perspective applied. Move the object 9 times the perspective, and the apparent size will be 1/10th.

See you snippet, with 2 opposite translateZ applied:

body {
    perspective: 100px;
}
.container, .title {
  transition: all 1s linear;
}
.image {
  background-image: url(https://www.w3schools.com/css/trolltunga.jpg);
  height: 300px;
  width: 800px;
}
.container {
  transform: translateZ(-900px);
  transform-origin: center bottom;
  transform-style: preserve-3d;
}
.container:hover {
  transform: translateZ(-100px);
}

.title {
  text-align: center;
  padding-top: 1rem;
  transform: translateZ(900px);
  transform-style: preserve-3d;
}

.container:hover .title {
  transform: translateZ(100px);
}

<div class="container">
   <div class="image"></div>
   <h1 class="title">Title</h1>
</div>


问:
Using SQL & Perl together - Which should be used for common functions?
I didn't find any dupes of this question, but if there is one or more, I'm sorry - please comment with link.

The question is basic, as probably is the answer.  If I'm using Perl to execute & act upon a database, which avenue (Perl vs. SQL) should I place the burden on when shared functions are involved?

Functions like - LEN, IF/ELSE, CONCAT and many more as well as arithmetic functions, for example are common to both systems.

This SQL statement is loaded with case blocks and other operations that can be replicated with Perl.  So, if the same logic could be implemented in Perl, is it worth re-writing?  What conditions influence the decision to take the burden of one system and place it on the other?

```<code>SELECT DISTINCT     s.id stu_id,
                    stu_id.fullname stu_name,
                    p.major1 major,
                    p.minor1 minor,
                    s.reg_hrs,
                    NVL(st.cum_earn_hrs,0) ttl_hrs,
                    p.adv_id curr_adv_id,
                    adv_id.fullname curr_adv_name,
                    CASE    WHEN    (p.adv_id <> 35808 AND p.major1 = 'NS')                 THEN    (1165)
                            WHEN    (p.adv_id = 35808 AND p.major1 = 'NS')                  THEN    (35808)
                            WHEN    (p.adv_id = 9179 AND p.major1 = 'DART')                 THEN    (9179)
                            WHEN    (p.minor1 IN ('RT','RESP') AND st.cum_earn_hrs >= 24)   THEN    (70897)
                            WHEN    (p.major1 IN ('CDSC','CDSD'))                           THEN    (52125)
                            WHEN    (p.major1 IN ('CA','CB'))                               THEN    (24702)
                            WHEN    (p.minor1 = 'NURS')                                     THEN    (51569)
                            WHEN    (p.major1 = 'LEG')                                      THEN    (13324)
                            WHEN    (p.major1 = 'CC')                                       THEN    (73837)
                            WHEN    (p.major1 = 'CCRE')                                     THEN    (1133)
                            WHEN    ((p.adv_id IN (SELECT DISTINCT id FROM fac_rec WHERE stat = 'I'))
                                    OR (st.cum_earn_hrs < 24 AND (p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0 AND min_hrs >= 24))
                                    OR (s.id NOT IN (SELECT DISTINCT stu.id FROM stu_acad_rec stu, sess_info si WHERE stu.yr = si.prev_yr AND stu.sess = si.prev_sess AND stu.reg_hrs > 0 AND stu.reg_stat IN ('C','R') AND stu.prog = 'UNDG'))
                                    OR ((p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat <> 'A' OR max_stu <= 0))
                                    OR ((p.adv_id||p.major1) NOT IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0)))
                            THEN    (9238)
                            ELSE    (p.adv_id)
                    END     new_adv_id,
                    CASE    WHEN    (p.adv_id <> 35808 AND p.major1 = 'NS')                 THEN    ('Deborah')
                            WHEN    (p.adv_id = 35808 AND p.major1 = 'NS')                  THEN    ('Veronica')
                            WHEN    (p.adv_id = 9179 AND p.major1 = 'DART')                 THEN    ('Stella')
                            WHEN    (p.minor1 IN ('RT','RESP') AND st.cum_earn_hrs >= 24)   THEN    ('Lisa')
                            WHEN    (p.major1 IN ('CDSC','CDSD'))                           THEN    ('Joanne')
                            WHEN    (p.major1 IN ('CA','CB'))                               THEN    ('Barbara')
                            WHEN    (p.minor1 = 'NURS')                                     THEN    ('Karen')
                            WHEN    (p.major1 = 'LEG')                                      THEN    ('Nancy')
                            WHEN    (p.major1 = 'CC')                                       THEN    ('Alberta')
                            WHEN    (p.major1 = 'CCRE')                                     THEN    ('Naomi')
                            WHEN    ((p.adv_id IN (SELECT DISTINCT id FROM fac_rec WHERE stat = 'I'))
                                    OR (st.cum_earn_hrs < 24 AND (p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0 AND min_hrs >= 24))
                                    OR (s.id NOT IN (SELECT DISTINCT stu.id FROM stu_acad_rec stu, sess_info si WHERE stu.yr = si.prev_yr AND stu.sess = si.prev_sess AND stu.reg_hrs > 0 AND stu.reg_stat IN ('C','R') AND stu.prog = 'UNDG'))
                                    OR ((p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat <> 'A' OR max_stu <= 0))
                                    OR ((p.adv_id||p.major1) NOT IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0)))
                            THEN    ('Staff')
                            ELSE    (adv_id.fullname)
                    END     new_adv_name,
                    CASE    WHEN    (p.adv_id <> 35808 AND p.major1 = 'NS')                 THEN    ('NS majors not assigned to Veronica go to Debbie')
                            WHEN    (p.adv_id = 35808 AND p.major1 = 'NS')                  THEN    ('NS majors stay with Veronica')
                            WHEN    (p.adv_id = 9179 AND p.major1 = 'DART')                 THEN    ('DART majors stay with Stella')
                            WHEN    (p.minor1 IN ('RT','RESP') AND st.cum_earn_hrs >= 24)   THEN    ('RT-RESP minors go to Lisa')
                            WHEN    (p.major1 IN ('CDSC','CDSD'))                           THEN    ('CDSC-CDSD majors go to Joanne')
                            WHEN    (p.major1 IN ('CA','CB'))                               THEN    ('CA-CB majors go to Barbara')
                            WHEN    (p.minor1 = 'NURS')                                     THEN    ('NURS minors go to Karen')
                            WHEN    (p.major1 = 'LEG')                                      THEN    ('LEG majors go to Nancy')
                            WHEN    (p.major1 = 'CC')                                       THEN    ('CC majors go to Alberta')
                            WHEN    (p.major1 = 'CCRE')                                     THEN    ('CCRE majors go to Naomi')
                            WHEN    (p.adv_id IN (SELECT DISTINCT id FROM fac_rec WHERE stat = 'I'))
                            THEN    ('Current advisor is inactive')
                            WHEN    (st.cum_earn_hrs < 24 AND (p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0 AND min_hrs >= 24))
                            THEN    ('Total credits for this student did not meet the advisor reqs for this major')
                            WHEN    (s.id NOT IN (SELECT DISTINCT stu.id FROM stu_acad_rec stu, sess_info si WHERE stu.yr = si.prev_yr AND stu.sess = si.prev_sess AND stu.reg_hrs > 0 AND stu.reg_stat IN ('C','R') AND stu.prog = 'UNDG'))
                            THEN    ('This student did not attend '||si.prev_sess||si.prev_yr)
                            WHEN    ((p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE (stat <> 'A' OR max_stu <= 0)))
                            THEN    ('Current advisor is not advising students with this major')
                            WHEN    ((p.adv_id||p.major1) NOT IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0))
                            THEN    ('Current advisor is not advising students with this major')
                            ELSE    ('Student will stay with current advisor')
                    END     change_comm
FROM                stu_acad_rec s,
                    prog_enr_rec p,
                    OUTER stu_stat_rec st,
                    id_rec stu_id,
                    id_rec adv_id,
                    sess_info si
WHERE               s.id = p.id
                    AND s.id = st.id
                    AND s.id = stu_id.id
                    AND p.adv_id = adv_id.id
                    AND s.yr = si.curr_yr
                    AND s.sess = si.curr_sess
                    AND s.reg_hrs > 0
                    AND s.reg_stat IN ('C','R')
                    AND s.prog = 'UNDG'
                    AND p.prog = 'UNDG'
                    AND st.prog = 'UNDG'
                    AND s.id NOT IN (3,287,9238,59999) {System test use IDs}
INTO TEMP           stu_list
WITH NO LOG;
</code>```

答:
Simple functions like LEN or SUM or COUNT are usually best done on SQL.

Those monster list of cases, on the other hand, I would probably keep in the application (and use a dictionary rather than loads of switches)

EDIT - or join to another table to eliminate many of those cases.  good answer Randy.  when you have that many cases it gets to the point that its data rather than logic, and the query shouldnt be holding data itself.

Body:
I didn't find any dupes of this question, but if there is one or more, I'm sorry - please comment with link.

The question is basic, as probably is the answer.  If I'm using Perl to execute & act upon a database, which avenue (Perl vs. SQL) should I place the burden on when shared functions are involved?

Functions like - LEN, IF/ELSE, CONCAT and many more as well as arithmetic functions, for example are common to both systems.

This SQL statement is loaded with case blocks and other operations that can be replicated with Perl.  So, if the same logic could be implemented in Perl, is it worth re-writing?  What conditions influence the decision to take the burden of one system and place it on the other?

SELECT DISTINCT     s.id stu_id,
                    stu_id.fullname stu_name,
                    p.major1 major,
                    p.minor1 minor,
                    s.reg_hrs,
                    NVL(st.cum_earn_hrs,0) ttl_hrs,
                    p.adv_id curr_adv_id,
                    adv_id.fullname curr_adv_name,
                    CASE    WHEN    (p.adv_id <> 35808 AND p.major1 = 'NS')                 THEN    (1165)
                            WHEN    (p.adv_id = 35808 AND p.major1 = 'NS')                  THEN    (35808)
                            WHEN    (p.adv_id = 9179 AND p.major1 = 'DART')                 THEN    (9179)
                            WHEN    (p.minor1 IN ('RT','RESP') AND st.cum_earn_hrs >= 24)   THEN    (70897)
                            WHEN    (p.major1 IN ('CDSC','CDSD'))                           THEN    (52125)
                            WHEN    (p.major1 IN ('CA','CB'))                               THEN    (24702)
                            WHEN    (p.minor1 = 'NURS')                                     THEN    (51569)
                            WHEN    (p.major1 = 'LEG')                                      THEN    (13324)
                            WHEN    (p.major1 = 'CC')                                       THEN    (73837)
                            WHEN    (p.major1 = 'CCRE')                                     THEN    (1133)
                            WHEN    ((p.adv_id IN (SELECT DISTINCT id FROM fac_rec WHERE stat = 'I'))
                                    OR (st.cum_earn_hrs < 24 AND (p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0 AND min_hrs >= 24))
                                    OR (s.id NOT IN (SELECT DISTINCT stu.id FROM stu_acad_rec stu, sess_info si WHERE stu.yr = si.prev_yr AND stu.sess = si.prev_sess AND stu.reg_hrs > 0 AND stu.reg_stat IN ('C','R') AND stu.prog = 'UNDG'))
                                    OR ((p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat <> 'A' OR max_stu <= 0))
                                    OR ((p.adv_id||p.major1) NOT IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0)))
                            THEN    (9238)
                            ELSE    (p.adv_id)
                    END     new_adv_id,
                    CASE    WHEN    (p.adv_id <> 35808 AND p.major1 = 'NS')                 THEN    ('Deborah')
                            WHEN    (p.adv_id = 35808 AND p.major1 = 'NS')                  THEN    ('Veronica')
                            WHEN    (p.adv_id = 9179 AND p.major1 = 'DART')                 THEN    ('Stella')
                            WHEN    (p.minor1 IN ('RT','RESP') AND st.cum_earn_hrs >= 24)   THEN    ('Lisa')
                            WHEN    (p.major1 IN ('CDSC','CDSD'))                           THEN    ('Joanne')
                            WHEN    (p.major1 IN ('CA','CB'))                               THEN    ('Barbara')
                            WHEN    (p.minor1 = 'NURS')                                     THEN    ('Karen')
                            WHEN    (p.major1 = 'LEG')                                      THEN    ('Nancy')
                            WHEN    (p.major1 = 'CC')                                       THEN    ('Alberta')
                            WHEN    (p.major1 = 'CCRE')                                     THEN    ('Naomi')
                            WHEN    ((p.adv_id IN (SELECT DISTINCT id FROM fac_rec WHERE stat = 'I'))
                                    OR (st.cum_earn_hrs < 24 AND (p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0 AND min_hrs >= 24))
                                    OR (s.id NOT IN (SELECT DISTINCT stu.id FROM stu_acad_rec stu, sess_info si WHERE stu.yr = si.prev_yr AND stu.sess = si.prev_sess AND stu.reg_hrs > 0 AND stu.reg_stat IN ('C','R') AND stu.prog = 'UNDG'))
                                    OR ((p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat <> 'A' OR max_stu <= 0))
                                    OR ((p.adv_id||p.major1) NOT IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0)))
                            THEN    ('Staff')
                            ELSE    (adv_id.fullname)
                    END     new_adv_name,
                    CASE    WHEN    (p.adv_id <> 35808 AND p.major1 = 'NS')                 THEN    ('NS majors not assigned to Veronica go to Debbie')
                            WHEN    (p.adv_id = 35808 AND p.major1 = 'NS')                  THEN    ('NS majors stay with Veronica')
                            WHEN    (p.adv_id = 9179 AND p.major1 = 'DART')                 THEN    ('DART majors stay with Stella')
                            WHEN    (p.minor1 IN ('RT','RESP') AND st.cum_earn_hrs >= 24)   THEN    ('RT-RESP minors go to Lisa')
                            WHEN    (p.major1 IN ('CDSC','CDSD'))                           THEN    ('CDSC-CDSD majors go to Joanne')
                            WHEN    (p.major1 IN ('CA','CB'))                               THEN    ('CA-CB majors go to Barbara')
                            WHEN    (p.minor1 = 'NURS')                                     THEN    ('NURS minors go to Karen')
                            WHEN    (p.major1 = 'LEG')                                      THEN    ('LEG majors go to Nancy')
                            WHEN    (p.major1 = 'CC')                                       THEN    ('CC majors go to Alberta')
                            WHEN    (p.major1 = 'CCRE')                                     THEN    ('CCRE majors go to Naomi')
                            WHEN    (p.adv_id IN (SELECT DISTINCT id FROM fac_rec WHERE stat = 'I'))
                            THEN    ('Current advisor is inactive')
                            WHEN    (st.cum_earn_hrs < 24 AND (p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0 AND min_hrs >= 24))
                            THEN    ('Total credits for this student did not meet the advisor reqs for this major')
                            WHEN    (s.id NOT IN (SELECT DISTINCT stu.id FROM stu_acad_rec stu, sess_info si WHERE stu.yr = si.prev_yr AND stu.sess = si.prev_sess AND stu.reg_hrs > 0 AND stu.reg_stat IN ('C','R') AND stu.prog = 'UNDG'))
                            THEN    ('This student did not attend '||si.prev_sess||si.prev_yr)
                            WHEN    ((p.adv_id||p.major1) IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE (stat <> 'A' OR max_stu <= 0)))
                            THEN    ('Current advisor is not advising students with this major')
                            WHEN    ((p.adv_id||p.major1) NOT IN (SELECT DISTINCT (id||major) FROM adv_detail WHERE stat = 'A' AND max_stu > 0))
                            THEN    ('Current advisor is not advising students with this major')
                            ELSE    ('Student will stay with current advisor')
                    END     change_comm
FROM                stu_acad_rec s,
                    prog_enr_rec p,
                    OUTER stu_stat_rec st,
                    id_rec stu_id,
                    id_rec adv_id,
                    sess_info si
WHERE               s.id = p.id
                    AND s.id = st.id
                    AND s.id = stu_id.id
                    AND p.adv_id = adv_id.id
                    AND s.yr = si.curr_yr
                    AND s.sess = si.curr_sess
                    AND s.reg_hrs > 0
                    AND s.reg_stat IN ('C','R')
                    AND s.prog = 'UNDG'
                    AND p.prog = 'UNDG'
                    AND st.prog = 'UNDG'
                    AND s.id NOT IN (3,287,9238,59999) {System test use IDs}
INTO TEMP           stu_list
WITH NO LOG;


问:
Upload two versions of an image (compressed and uncompressed) using CarrierWave in Rails
I am using Carrierwave and S3 to store images uploaded by the user in my rails app.

I want to store 2 versions of the image - one is the original, uncompressed image and the other is its compressed version. How do I do that?

答:
You can add to your uploader:

```<code>version :name_of_your_version do
  process resize_to_fit: [200,200]
end
</code>```

Inside the block you can pass whatever processes you want and these will be executed and saved on a version called name_of_your_version.

Body:
You can add to your uploader:

version :name_of_your_version do
  process resize_to_fit: [200,200]
end

Inside the block you can pass whatever processes you want and these will be executed and saved on a version called name_of_your_version.


问:
returns the exact returned value if wget fails
I'd love to return the exact value if wget command fails in efficient way without changing it.

Can exit #? output the returned value from wget?

Ex.

```<code># If it succeeds, then wget returns zero instead of non zero
## 0    No problems occurred.
## 1    Generic error code.
## 2    Parse error—for instance, when parsing command-line options, the ‘.wgetrc’ or ‘.netrc’...
## 3    File I/O error.
## 4    Network failure.
## 5    SSL verification failure.
## 6    Username/password authentication failure.
## 7    Protocol errors.
## 8    Server issued an error response.
wget https://www.google.co.jp/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png -o test.img
if [ $? -ne 0 ]
then
    # exit 16 # failed ends1 <== This doesn't tell anything
    exit #?
fi
</code>```

答:
The -e option of Bash may do what you want:

Exit  immediately  if  a pipeline (which may consist of a single simple command), a list, or a compound command (see SHELL GRAMMAR), exits with a non-zero status.

It's also important to know that

Bash's exit status  is the  exit  status  of  the last command executed in the script.

My experiments with Bash 4.4 suggest that the exit status of the failing command is returned, even if a trap handler is invoked:

```<code>$ ( trap 'echo $?' ERR; set -e; ( exit 3 ) ; echo true ) ; echo $?
3
3
</code>```

So you can write:

```<code>#!/bin/bash

url=https://www.google.co.jp/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png

set -e
wget -o test.img "$url"
set +e    # if you no longer want exit on fail
</code>```

For just one command in your script, you might prefer an explicit test and exit like this:

```<code>wget -o test.img "$url"  || exit $?
</code>```

Further, exit with no argument is the same as exit $?, so that can be simplified to just

```<code>wget -o test.img "$url"  || exit
</code>```

Body:
I'd love to return the exact value if wget command fails in efficient way without changing it.

Can exit #? output the returned value from wget?

Ex.

# If it succeeds, then wget returns zero instead of non zero
## 0    No problems occurred.
## 1    Generic error code.
## 2    Parse error—for instance, when parsing command-line options, the ‘.wgetrc’ or ‘.netrc’...
## 3    File I/O error.
## 4    Network failure.
## 5    SSL verification failure.
## 6    Username/password authentication failure.
## 7    Protocol errors.
## 8    Server issued an error response.
wget https://www.google.co.jp/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png -o test.img
if [ $? -ne 0 ]
then
    # exit 16 # failed ends1 <== This doesn't tell anything
    exit #?
fi

Body:
The -e option of Bash may do what you want:

Exit  immediately  if  a pipeline (which may consist of a single simple command), a list, or a compound command (see SHELL GRAMMAR), exits with a non-zero status.

It's also important to know that

Bash's exit status  is the  exit  status  of  the last command executed in the script.

My experiments with Bash 4.4 suggest that the exit status of the failing command is returned, even if a trap handler is invoked:

$ ( trap 'echo $?' ERR; set -e; ( exit 3 ) ; echo true ) ; echo $?
3
3

So you can write:

#!/bin/bash

url=https://www.google.co.jp/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png

set -e
wget -o test.img "$url"
set +e    # if you no longer want exit on fail

For just one command in your script, you might prefer an explicit test and exit like this:

wget -o test.img "$url"  || exit $?

Further, exit with no argument is the same as exit $?, so that can be simplified to just

wget -o test.img "$url"  || exit