问:
How to order months between two years in SSRS
I have the following table in SQL:

```<code>UniqueUsers YEAR     MONTH     MONTH2
NULL        NULL     January     1
NULL        NULL     February    2
NULL        NULL     July        7
NULL        NULL     August      8
NULL        NULL     September   9
NULL        NULL     October     10
NULL        NULL     November    11
NULL        NULL     December    12
1           2016     March       3
2           2016     April       4
2           2016     May         5
1           2016     June        6
</code>```

In SSRS I have a table grouped by Month with 4 parameters: 1 for Year1 and 1 for Month1; 1 for Year2 and 1 for Month2.

For example, if I select Year1 = 2015 and Month1 = November and December and Year2 = 2016 and Month2 = January and February I need to show the months like this even if the results have NULL values:

```<code>Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct
</code>```

This is the query than I use:

```<code>SELECT *
FROM
(
SELECT
      [QUARTER]
      ,[CARRIER]
      ,[PLANGROUP]
      ,[UniqueUsers]
      ,[YEAR]
      ,A.[MONTH]
      ,A.[MONTH2]
FROM [ReportUnit].[dbo].[Month_List] A

LEFT JOIN

(SELECT
        [YEAR]
        ,[MONTH2]
        ,[CARRIER]
        ,[PLANGROUP]
        ,[QUARTER]
        ,COUNT(DISTINCT [CONTRACT_NUM]) AS [UniqueUsers]
FROM
(
SELECT *
FROM
(
SELECT
        MIN([YEAR]) AS [YEAR]
        ,MIN([MONTH2]) AS [MONTH2]
        ,DATENAME(MONTH, DATEADD(MONTH, MIN([MONTH2])-1, CAST('2017-01-01' AS datetime))) AS [MONTH]
        ,[CARRIER]
        ,[PLANGROUP]
        ,MIN([QUARTER]) AS [QUARTER]
        ,[CONTRACT_NUM]
FROM MyTable
WHERE
[YEAR] = @YEAR1
AND [PLANGROUP] IN (@ACCOUNT)
GROUP BY [PLANGROUP],[CARRIER],[CONTRACT_NUM]
) Q1
WHERE
[MONTH] IN (@MONTH1) --THIS IS MONTH NAME PARAMETER IN SSRS
--[MONTH2] IN (11,12)

UNION ALL

SELECT *
FROM
(
SELECT
        MIN([YEAR]) AS [YEAR]
        ,MIN([MONTH2]) AS [MONTH2]
        ,DATENAME(MONTH, DATEADD(MONTH, MIN([MONTH2])-1, CAST('2017-01-01' AS datetime))) AS [MONTH]
        ,[CARRIER]
        ,[PLANGROUP]
        ,MIN([QUARTER]) AS [QUARTER]
        ,[CONTRACT_NUM]
FROM MyTable
WHERE
[YEAR] = @YEAR2
AND [PLANGROUP] IN (@ACCOUNT)
GROUP BY [PLANGROUP],[CARRIER],[CONTRACT_NUM]
) Q1
WHERE
[MONTH] IN (@MONTH2)  --THIS IS MONTH NAME PARAMETER IN SSRS
--[MONTH2] IN (1,2,3,4,5,6,7,8,9,10)
) Q1
GROUP BY [YEAR],[MONTH2],[PLANGROUP],[CARRIER],[QUARTER]
) B ON A.MONTH2 = B.MONTH2
) Q4
ORDER BY [PLANGROUP], [YEAR], [MONTH2], [MONTH]
</code>```

答:
The best way to handle these kind of things is create a date table. How detailed that is, is down to your requirements. In your case you may only need months and years, although if you data is more detailed you may need all dates. You can then use this table and left join your main data to it.

The other option is to build a temp table in your dataset with your months and years in it.

I didn't quite understand what parameters you are passing so I'll just have a guess, hopefully this will give you enough to go on anyway. This assumes you are only ever working with data from no more than 2 years, if not then you are probably better to go down the permanent date table route...

So, if you pass in 4 parameters to your dataset query as 2015; 11; 2016; 10 (Nov'15 to Oct'16)

The your dataset query would look something like.

```<code>/* uncomment for testing on SSMS only
DECLARE @Year1 int = 2015
DECLARE @Year2 int = 2016
DECLARE @Month1 int = 11
DECLARE @Month2 int = 10
*/

/*Create temp Dates Table*/
DECLARE @d TABLE([Year] int, [Month] int)
INSERT INTO @d
SELECT @Year1, 1 UNION
SELECT @Year1, 2 UNION
SELECT @Year1, 3 UNION
SELECT @Year1, 4 UNION
SELECT @Year1, 5 UNION
SELECT @Year1, 6 UNION
SELECT @Year1, 7 UNION
SELECT @Year1, 8 UNION
SELECT @Year1, 9 UNION
SELECT @Year1, 10 UNION
SELECT @Year1, 11 UNION
SELECT @Year1, 12 UNION
SELECT @Year2, 1 UNION
SELECT @Year2, 2 UNION
SELECT @Year2, 3 UNION
SELECT @Year2, 4 UNION
SELECT @Year2, 5 UNION
SELECT @Year2, 6 UNION
SELECT @Year2, 7 UNION
SELECT @Year2, 8 UNION
SELECT @Year2, 9 UNION
SELECT @Year2, 10 UNION
SELECT @Year2, 11 UNION
SELECT @Year2, 12

SELECT d.[Year], d.[Month], t.myColumns
    FROM @d d
       LEFT JOIN myTable t on d.[Year] = t.[Year] and d.[Month] = t.[Month]
    WHERE
       ((t.[Year] *100) + t.[Month]) between (@Year1 *100 + @Month1) and (@Year2 *100 + @Month2)
    ORDER by d.[Year], d.[Month]
</code>```

Body:
I have the following table in SQL:

UniqueUsers YEAR     MONTH     MONTH2
NULL        NULL     January     1
NULL        NULL     February    2
NULL        NULL     July        7
NULL        NULL     August      8
NULL        NULL     September   9
NULL        NULL     October     10
NULL        NULL     November    11
NULL        NULL     December    12
1           2016     March       3
2           2016     April       4
2           2016     May         5
1           2016     June        6

In SSRS I have a table grouped by Month with 4 parameters: 1 for Year1 and 1 for Month1; 1 for Year2 and 1 for Month2.

For example, if I select Year1 = 2015 and Month1 = November and December and Year2 = 2016 and Month2 = January and February I need to show the months like this even if the results have NULL values:

Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct

This is the query than I use:

SELECT *
FROM
(
SELECT
      [QUARTER]
      ,[CARRIER]
      ,[PLANGROUP]
      ,[UniqueUsers]
      ,[YEAR]
      ,A.[MONTH]
      ,A.[MONTH2]
FROM [ReportUnit].[dbo].[Month_List] A

LEFT JOIN

(SELECT
        [YEAR]
        ,[MONTH2]
        ,[CARRIER]
        ,[PLANGROUP]
        ,[QUARTER]
        ,COUNT(DISTINCT [CONTRACT_NUM]) AS [UniqueUsers]
FROM
(
SELECT *
FROM
(
SELECT
        MIN([YEAR]) AS [YEAR]
        ,MIN([MONTH2]) AS [MONTH2]
        ,DATENAME(MONTH, DATEADD(MONTH, MIN([MONTH2])-1, CAST('2017-01-01' AS datetime))) AS [MONTH]
        ,[CARRIER]
        ,[PLANGROUP]
        ,MIN([QUARTER]) AS [QUARTER]
        ,[CONTRACT_NUM]
FROM MyTable
WHERE
[YEAR] = @YEAR1
AND [PLANGROUP] IN (@ACCOUNT)
GROUP BY [PLANGROUP],[CARRIER],[CONTRACT_NUM]
) Q1
WHERE
[MONTH] IN (@MONTH1) --THIS IS MONTH NAME PARAMETER IN SSRS
--[MONTH2] IN (11,12)

UNION ALL

SELECT *
FROM
(
SELECT
        MIN([YEAR]) AS [YEAR]
        ,MIN([MONTH2]) AS [MONTH2]
        ,DATENAME(MONTH, DATEADD(MONTH, MIN([MONTH2])-1, CAST('2017-01-01' AS datetime))) AS [MONTH]
        ,[CARRIER]
        ,[PLANGROUP]
        ,MIN([QUARTER]) AS [QUARTER]
        ,[CONTRACT_NUM]
FROM MyTable
WHERE
[YEAR] = @YEAR2
AND [PLANGROUP] IN (@ACCOUNT)
GROUP BY [PLANGROUP],[CARRIER],[CONTRACT_NUM]
) Q1
WHERE
[MONTH] IN (@MONTH2)  --THIS IS MONTH NAME PARAMETER IN SSRS
--[MONTH2] IN (1,2,3,4,5,6,7,8,9,10)
) Q1
GROUP BY [YEAR],[MONTH2],[PLANGROUP],[CARRIER],[QUARTER]
) B ON A.MONTH2 = B.MONTH2
) Q4
ORDER BY [PLANGROUP], [YEAR], [MONTH2], [MONTH]

Body:
The best way to handle these kind of things is create a date table. How detailed that is, is down to your requirements. In your case you may only need months and years, although if you data is more detailed you may need all dates. You can then use this table and left join your main data to it.

The other option is to build a temp table in your dataset with your months and years in it.

I didn't quite understand what parameters you are passing so I'll just have a guess, hopefully this will give you enough to go on anyway. This assumes you are only ever working with data from no more than 2 years, if not then you are probably better to go down the permanent date table route...

So, if you pass in 4 parameters to your dataset query as 2015; 11; 2016; 10 (Nov'15 to Oct'16)

The your dataset query would look something like.

/* uncomment for testing on SSMS only
DECLARE @Year1 int = 2015
DECLARE @Year2 int = 2016
DECLARE @Month1 int = 11
DECLARE @Month2 int = 10
*/

/*Create temp Dates Table*/
DECLARE @d TABLE([Year] int, [Month] int)
INSERT INTO @d
SELECT @Year1, 1 UNION
SELECT @Year1, 2 UNION
SELECT @Year1, 3 UNION
SELECT @Year1, 4 UNION
SELECT @Year1, 5 UNION
SELECT @Year1, 6 UNION
SELECT @Year1, 7 UNION
SELECT @Year1, 8 UNION
SELECT @Year1, 9 UNION
SELECT @Year1, 10 UNION
SELECT @Year1, 11 UNION
SELECT @Year1, 12 UNION
SELECT @Year2, 1 UNION
SELECT @Year2, 2 UNION
SELECT @Year2, 3 UNION
SELECT @Year2, 4 UNION
SELECT @Year2, 5 UNION
SELECT @Year2, 6 UNION
SELECT @Year2, 7 UNION
SELECT @Year2, 8 UNION
SELECT @Year2, 9 UNION
SELECT @Year2, 10 UNION
SELECT @Year2, 11 UNION
SELECT @Year2, 12

SELECT d.[Year], d.[Month], t.myColumns
    FROM @d d
       LEFT JOIN myTable t on d.[Year] = t.[Year] and d.[Month] = t.[Month]
    WHERE
       ((t.[Year] *100) + t.[Month]) between (@Year1 *100 + @Month1) and (@Year2 *100 + @Month2)
    ORDER by d.[Year], d.[Month]


来源: stackexchange

问:
How to Listen events in node-red - hyperledger composer
I have deployed my business network using node-red and local composer over fabric. I would like to listen to an event in node-red. I am able to submit the transaction successfully but not able to see the notification emitted by event in the same transaction on debug console in node-red.

composer nodes are latest and Composer is 0.16v. Event url port is 7053. I have attached two images below.

Transaction Submitted - shipmentreceived. When the transaction processor function is executed for this transaction, event is emitted as mentioned below:

```<code>    var basicEvent=getFactory().newEvent('org.acme.shipping.perishable','ShipmentNotification');
    basicEvent.shipmentStatus = shipment.status;
    emit(basicEvent);
</code>```

Model File:

```<code>    event ShipmentNotification{
      o String shipmentStatus
    }
</code>```

Node-red - Submitting and Listening event

This could be error

答:
see https://medium.com/@CazChurchUk/integrate-your-blockchain-with-anything-using-hyperledger-composer-and-nodered-4226676f7e54

it needs to be updated to use 'business network cards' not 'profiles' in the NodeRed node widgets / flow,  but the same principle applies where subscribing to events are concerned.

ContentLicense: CC BY-SA 3.0

Body:
I have deployed my business network using node-red and local composer over fabric. I would like to listen to an event in node-red. I am able to submit the transaction successfully but not able to see the notification emitted by event in the same transaction on debug console in node-red.

composer nodes are latest and Composer is 0.16v. Event url port is 7053. I have attached two images below.

Transaction Submitted - shipmentreceived. When the transaction processor function is executed for this transaction, event is emitted as mentioned below:

    var basicEvent=getFactory().newEvent('org.acme.shipping.perishable','ShipmentNotification');
    basicEvent.shipmentStatus = shipment.status;
    emit(basicEvent);

Model File:

    event ShipmentNotification{
      o String shipmentStatus
    }

Node-red - Submitting and Listening event

This could be error


问:
Visual Studio 2017 bin\roslyn files locked during build
I am running VS2017 version 26430.13 and every time I try to build a web project I get errors that access to the files in the bin\roslyn is denied.
Over a period of about 5 minutes the files are unlocked and I can build but the 5 minute delay is unacceptable.

These are the files that stay locked:

Microsoft.CodeAnalysis.CSharp.dll

Microsoft.CodeAnalysis.dll

Microsoft.CodeAnalysis.VisualBasic.dll

Microsoft.DiaSymReader.Native.amd64.dll

System.Collections.Immutable.dll

System.Diagnostics.FileVersionInfo.dll

System.IO.Compression.dll

System.IO.FileSystem.dll

System.IO.FileSystem.Primitives.dll

System.Reflection.Metadata.dll

System.Security.Cryptography.Algorithms.dl

System.Security.Cryptography.Primitives.dl

System.ValueTuple.dll

VBCSCompiler.exe

答:
In my case I did these two steps:

uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -Version 1.0.8


问:
How to get a list of warnings from sphinx compilation
I am developing a sphinx based collaborative writing tool. Users access the web application (developed in python/Flask) to write a book in sphinx and compile it to pdf.

I have learned that in order to compile a sphinx documentation from within python I should use

```<code>import sphinx
result = sphinx.build_main(['-c', 'path/to/conf',
                            'path/to/source/', 'path/to/out'])
</code>```

So far so good.

Now my users want the app to show them their syntax mistakes. But the output (result in the example above) only gives me the exit code.

So, how do I get a list of warnings from the build process?

Perhaps I am being too ambitious, but since sphinx is a python tool, I was expecting to have a nice pythonic interface with the tool. For example, the output of sphinx.build_main could be a very rich object with warnings, line numbers...

On a related note, the argument to the method sphinx.build_main looks just like a wrapper to the command line interface.

答:
sphinx.build_main() calls sphinx.cmdline.main(), which in turn creates a sphinx.application.Sphinx object. You could create such an object directly (instead of "making system calls within python"). Use something like this:

```<code>import os
from sphinx.application import Sphinx

# Main arguments
srcdir = "/path/to/source"
confdir = srcdir
builddir = os.path.join(srcdir, "_build")
doctreedir = os.path.join(builddir, "doctrees")
builder = "html"

# Write warning messages to a file (instead of stderr)
warning = open("/path/to/warnings.txt", "w")

# Create the Sphinx application object
app = Sphinx(srcdir, confdir, builddir, doctreedir, builder,
             warning=warning)

# Run the build
app.build()
</code>```

Body:
I am developing a sphinx based collaborative writing tool. Users access the web application (developed in python/Flask) to write a book in sphinx and compile it to pdf.

I have learned that in order to compile a sphinx documentation from within python I should use

import sphinx
result = sphinx.build_main(['-c', 'path/to/conf',
                            'path/to/source/', 'path/to/out'])

So far so good.

Now my users want the app to show them their syntax mistakes. But the output (result in the example above) only gives me the exit code.

So, how do I get a list of warnings from the build process?

Perhaps I am being too ambitious, but since sphinx is a python tool, I was expecting to have a nice pythonic interface with the tool. For example, the output of sphinx.build_main could be a very rich object with warnings, line numbers...

On a related note, the argument to the method sphinx.build_main looks just like a wrapper to the command line interface.

Body:
sphinx.build_main() calls sphinx.cmdline.main(), which in turn creates a sphinx.application.Sphinx object. You could create such an object directly (instead of "making system calls within python"). Use something like this:

import os
from sphinx.application import Sphinx

# Main arguments
srcdir = "/path/to/source"
confdir = srcdir
builddir = os.path.join(srcdir, "_build")
doctreedir = os.path.join(builddir, "doctrees")
builder = "html"

# Write warning messages to a file (instead of stderr)
warning = open("/path/to/warnings.txt", "w")

# Create the Sphinx application object
app = Sphinx(srcdir, confdir, builddir, doctreedir, builder,
             warning=warning)

# Run the build
app.build()


问:
List.set replacing all indexes inside TreeMap

I have a TreeMap<String, List<Double> that I would like to pull out the List at a certain key, add a value at a certain index and then put it back into the TreeMap.

At the time of the below code, the TreeMap contains:

{specificKey=[0,0,0], specificKey2=[0,0,0], specificKey3=[0,0,0]}

I want to add the value to specificKey at index 0, so {specificKey=[777,0,0], specificKey2=[0,0,0], specificKey3=[0,0,0]}

Here is the offending code...

```<code>if (myMap.containsKey(specificKey){
    List<Double> doubleList = myMap.get(specificKey);
    doubleList.set(0, someValue);
    myMap.put(specificKey, doubleList);
}
</code>```

Instead, what happens is: {specificKey=[777,0,0], specificKey2=[777,0,0], specificKey3=[777,0,0]}

Why is this happening when I am pulling out the exact List with myMap.get(specificKey)? And any ideas on how to accomplish what I need?

答:
You are doing everything right. Moreover, you can remove myMap.put(specificKey, doubleList), because the list is already there.

The reason why this happens in your scenario is that all three keys refer to the same instance of List<Double> that you created when populating your TreeMap. Change the code to insert new lists for each key to fix this problem:

```<code>myMap.put(specificKey1, new ArrayList<Double>(Collections.nCopies(3, Double.valueOf(0))));
myMap.put(specificKey2, new ArrayList<Double>(Collections.nCopies(3, Double.valueOf(0))));
myMap.put(specificKey3, new ArrayList<Double>(Collections.nCopies(3, Double.valueOf(0))));
...
if (myMap.containsKey(specificKey1){
    myMap.get(specificKey1).set(0, someValue);
}
</code>```

Body:
I have a TreeMap<String, List<Double> that I would like to pull out the List at a certain key, add a value at a certain index and then put it back into the TreeMap.

At the time of the below code, the TreeMap contains:

{specificKey=[0,0,0], specificKey2=[0,0,0], specificKey3=[0,0,0]}

I want to add the value to specificKey at index 0, so {specificKey=[777,0,0], specificKey2=[0,0,0], specificKey3=[0,0,0]}

Here is the offending code...

if (myMap.containsKey(specificKey){
    List<Double> doubleList = myMap.get(specificKey);
    doubleList.set(0, someValue);
    myMap.put(specificKey, doubleList);
}

Instead, what happens is: {specificKey=[777,0,0], specificKey2=[777,0,0], specificKey3=[777,0,0]}

Why is this happening when I am pulling out the exact List with myMap.get(specificKey)? And any ideas on how to accomplish what I need?

Body:
You are doing everything right. Moreover, you can remove myMap.put(specificKey, doubleList), because the list is already there.

The reason why this happens in your scenario is that all three keys refer to the same instance of List<Double> that you created when populating your TreeMap. Change the code to insert new lists for each key to fix this problem:

myMap.put(specificKey1, new ArrayList<Double>(Collections.nCopies(3, Double.valueOf(0))));
myMap.put(specificKey2, new ArrayList<Double>(Collections.nCopies(3, Double.valueOf(0))));
myMap.put(specificKey3, new ArrayList<Double>(Collections.nCopies(3, Double.valueOf(0))));
...
if (myMap.containsKey(specificKey1){
    myMap.get(specificKey1).set(0, someValue);
}


问:
Is it possible to get an rss feed using javascript client side scripting only?
If I can't do this would the process for getting the data be:
1) Have my server get the rss data from the desired rss feed.
2) Have the server parse the data.  I don't know what rss looks like but I assume some parsing     is needed to display it for a user to read.
3) Send the data to the javascript client.</p>

答:
Another option is to use postrank's api.  http://apidocs.postrank.com/w/page/17907957/Feed-API or http://apidocs.postrank.com/w/page/17907977/Top-Posts-API.

They have some options to filter or return only the top posts.  plus you can pass it a callback for jsonp fun.

ContentLicense: CC BY-SA 2.5


问:
invalid distance too far back
I'm using org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream; and error invalid distance too far backis occured. I don't know what this error means. Exists some documentation for that ? Or any solution how to repair that.

答: It means that the input is either corrupted, or that it isn't deflate compressed data in the first place.</p>

Title: invalid distance too far back


问:
Class instance of two variables
I'm very new to Haskell and created this class

```<code>class Printable a where
    toString :: a -> String
</code>```

And two of its instances

```<code>instance Printable Bool where
    toString x | x == True = "true"
               | x == False  = "false"

instance Printable () where
    toString x = "unit type"
</code>```

They work just fine, and now I want to create an instance that would take two parameters, but I'm having troubles. What I created so far is

```<code>instance (Printable a, Printable b) => Printable (a, b) where
    toString x | fst x == True = "(true,unit type)"
</code>```

But now I get the error

Couldn't match expected type ‘a’ with actual type ‘Bool’

which is reasonable, but when I replace a with Bool I also get an error. How can I make it work in the first place, and can I restrict the types for a and b - for example, what if I want a to always be Bool and b to always be ()?

答:
You wrote an instance where you write that for a tuple (a, b), the tuple is Printable in case the items a and b are Printable. But that does not mean that a or b are Bools, or units.

You may think that - like in many languages - the (==) operator works on any two types, but in Haskell (==) has type (==) :: Eq a => a -> a -> Bool, so it is a function where the left and the right operand have the same type. So we can not use x == True, unless x is a Bool.

We do not need these guards. What we need to do is call the toString function of the operands, so:

```<code>instance (Printable a, Printable b) => Printable (a, b) where
    toString <b>(x,y)</b> = "("<b> ++ toString x ++</b> "," ++ <b>toString y ++</b> ")"</code>```

We can also replace [x] ++ with x : ... so we can rewrite it to:

```<code>instance (Printable a, Printable b) => Printable (a, b) where
    toString (x,y) = <b>'(' : </b> toString x ++ <b>',' :</b> toString y ++<b> ")"</b></code>```

EDIT: in case you want a to be always a Bool, you can write:

```<code>instance <b>Printable b</b> => Printable (<b>Bool</b>, b) where
    toString (x,y) = '(' :  toString x ++ ',' : toString y ++ ")"</code>```

You can of course now add guards, pattern matching, or some other method to discriminate between x == True and x == False, but I advice you not to do this, since this violates the DRY principle: Don't Repeat Yourself.

Title: Class instance of two variables

Body:
I'm very new to Haskell and created this class

class Printable a where
    toString :: a -> String

And two of its instances

instance Printable Bool where
    toString x | x == True = "true"
               | x == False  = "false"

instance Printable () where
    toString x = "unit type"

They work just fine, and now I want to create an instance that would take two parameters, but I'm having troubles. What I created so far is

instance (Printable a, Printable b) => Printable (a, b) where
    toString x | fst x == True = "(true,unit type)"

But now I get the error

Couldn't match expected type ‘a’ with actual type ‘Bool’

which is reasonable, but when I replace a with Bool I also get an error. How can I make it work in the first place, and can I restrict the types for a and b - for example, what if I want a to always be Bool and b to always be ()?

Body:
You wrote an instance where you write that for a tuple (a, b), the tuple is Printable in case the items a and b are Printable. But that does not mean that a or b are Bools, or units.

You may think that - like in many languages - the (==) operator works on any two types, but in Haskell (==) has type (==) :: Eq a => a -> a -> Bool, so it is a function where the left and the right operand have the same type. So we can not use x == True, unless x is a Bool.

We do not need these guards. What we need to do is call the toString function of the operands, so:

instance (Printable a, Printable b) => Printable (a, b) where
    toString (x,y) = "(" ++ toString x ++ "," ++ toString y ++ ")"

We can also replace [x] ++ with x : ... so we can rewrite it to:

instance (Printable a, Printable b) => Printable (a, b) where
    toString (x,y) = '(' :  toString x ++ ',' : toString y ++ ")"

EDIT: in case you want a to be always a Bool, you can write:

instance Printable b => Printable (Bool, b) where
    toString (x,y) = '(' :  toString x ++ ',' : toString y ++ ")"

You can of course now add guards, pattern matching, or some other method to discriminate between x == True and x == False, but I advice you not to do this, since this violates the DRY principle: Don't Repeat Yourself.


问:
SQL procedure to show how many hours has worker worked
```<code>+-----------+-------------------------------+-------+
| Worker ID | Time(MM/DD/YYYY Hour:Min:Sec) | InOut |
+-----------+-------------------------------+-------+
|        1  |  12/04/2017 10:00:00          | In    |
|        2  |  12/04/2017 10:00:00          | In    |
|        2  |  12/04/2017 18:40:02          | Out   |
|        3  |  12/04/2017 10:00:00          | In    |
|        1  |  12/04/2017 12:01:00          | Out   |
|        3  |  12/04/2017 19:40:05          | Out   |
+-----------+-------------------------------+-------+
</code>```

Hi! I have problem with my project and I thought some of you would help me. I have table like that. It is simple table that indicates worker getting in and out of company. I need to do procedure which would take ID and number of day as In parameters and it would show how many hours and minutes that worker has worked that day. Thanks for help.

答:
I'm fairly certain Oracle allows you to use CROSS APPLY these days.

```<code>SELECT [Worker ID], yt.Time - ca.Time
FROM YourTable yt
CROSS APPLY (SELECT MAX(Time) AS Time
             FROM YourTable
             WHERE [Worker ID] = yt.[Worker ID] AND Time < yt.Time AND InOut = 'In') ca
WHERE yt.InOut = 'Out'
</code>```

Body:
+-----------+-------------------------------+-------+
| Worker ID | Time(MM/DD/YYYY Hour:Min:Sec) | InOut |
+-----------+-------------------------------+-------+
|        1  |  12/04/2017 10:00:00          | In    |
|        2  |  12/04/2017 10:00:00          | In    |
|        2  |  12/04/2017 18:40:02          | Out   |
|        3  |  12/04/2017 10:00:00          | In    |
|        1  |  12/04/2017 12:01:00          | Out   |
|        3  |  12/04/2017 19:40:05          | Out   |
+-----------+-------------------------------+-------+

Hi! I have problem with my project and I thought some of you would help me. I have table like that. It is simple table that indicates worker getting in and out of company. I need to do procedure which would take ID and number of day as In parameters and it would show how many hours and minutes that worker has worked that day. Thanks for help.

Body:
I'm fairly certain Oracle allows you to use CROSS APPLY these days.

SELECT [Worker ID], yt.Time - ca.Time
FROM YourTable yt
CROSS APPLY (SELECT MAX(Time) AS Time
             FROM YourTable
             WHERE [Worker ID] = yt.[Worker ID] AND Time < yt.Time AND InOut = 'In') ca
WHERE yt.InOut = 'Out'


答:
You have populated the map with three instances of the same list object. You need to create three distinct lists. For example:</p>

```<code>TreeMap<String, List<Double>> myMap = new TreeMap<>();
myMap.put(specificKey,  Arrays.asList(0.0, 0.0, 0.0));
myMap.put(specificKey2, Arrays.asList(0.0, 0.0, 0.0));
myMap.put(specificKey3, Arrays.asList(0.0, 0.0, 0.0));
</code>```

Title: List.set replacing all indexes inside TreeMap

Body:
You have populated the map with three instances of the same list object. You need to create three distinct lists. For example:

TreeMap<String, List<Double>> myMap = new TreeMap<>();
myMap.put(specificKey,  Arrays.asList(0.0, 0.0, 0.0));
myMap.put(specificKey2, Arrays.asList(0.0, 0.0, 0.0));
myMap.put(specificKey3, Arrays.asList(0.0, 0.0, 0.0));


问:
Transparent Networx Edge Labels
How to set transparent edge labels in NetworkX graph? Currently there is a white background to each label which cuts my edges and overlaps other labels</p>

```<code>nx.draw(v29graph,
        nx.get_node_attributes(v29graph,'pos'),
        edge_labels=labels2
        )

nx.draw_networkx_edge_labels(v29graph,
                             pos=nx.get_node_attributes(v29graph,'pos'),
                             edge_labels=labels2
                             )
</code>```

答:
You can use the bbox argument:

```<code>nx.draw_networkx_edge_labels(v29graph,
                             pos=nx.get_node_attributes(v29graph,'pos'),
                             edge_labels=labels2,
                             bbox=dict(alpha=0)
                             )
</code>```

More bbox style examples are here.

ContentLicense: CC BY-SA 4.0

Title: Transparent Networx Edge Labels

Body:
How to set transparent edge labels in NetworkX graph? Currently there is a white background to each label which cuts my edges and overlaps other labels

nx.draw(v29graph,
        nx.get_node_attributes(v29graph,'pos'),
        edge_labels=labels2
        )

nx.draw_networkx_edge_labels(v29graph,
                             pos=nx.get_node_attributes(v29graph,'pos'),
                             edge_labels=labels2
                             )

Body:
You can use the bbox argument:

nx.draw_networkx_edge_labels(v29graph,
                             pos=nx.get_node_attributes(v29graph,'pos'),
                             edge_labels=labels2,
                             bbox=dict(alpha=0)
                             )

More bbox style examples are here.


问:
selector not sent by methodSignatureForSelector to forwardInvocation
I'm trying to change which method is called on an object for the sake of learning.
Here is my code.

```<code>#import <Foundation/Foundation.h>

@interface A : NSObject
-(void) say: (NSString*) s;
-(NSMethodSignature*) methodSignatureForSelector: (SEL) aSelector;
-(void) forwardInvocation: (NSInvocation*) invocation;
@end

@implementation A
-(void) say: (NSString*) s {
  printf( "say \"%s\"", [s UTF8String] );
}
-(NSMethodSignature*) methodSignatureForSelector: (SEL) aSelector {
  return [A instanceMethodSignatureForSelector: @selector(say:)];
}
-(void) forwardInvocation: (NSInvocation*) invocation {
  // [invocation setSelector:@selector(say:)];
  [invocation invokeWithTarget:self];
}
@end

int main(int args, char* argv[]){
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  A* myObject = [[[A alloc] init] autorelease];

  [myObject tryToSay:@"Hello strange method!"];

  [pool release];
  return 0;
}
</code>```

I want to use -say: no matter which method is attempted used on objects of the class A.

The result is a Segfault.
It seems the invocation object sent to forwardInvocation still has @selector(tryToSay:) as its selector. Is it not supposed to get the same selector that was set in methodSignatureForSelector?

答: No, it's not. NSMethodSignature doesn't encode the selector. It encodes the signature of the method instead. This means things like the type and number of arguments. It's also not going to work correctly. If someone tries to invoke a method like -setInteger: which takes an NSUInteger, it will be passed to your method -say: which is expecting an NSString*. But it won't get an NSString*, it will get an NSUInteger, and any attempt to dereference that will crash (unless it's 0).

Body:
I'm trying to change which method is called on an object for the sake of learning.
Here is my code.

#import <Foundation/Foundation.h>

@interface A : NSObject
-(void) say: (NSString*) s;
-(NSMethodSignature*) methodSignatureForSelector: (SEL) aSelector;
-(void) forwardInvocation: (NSInvocation*) invocation;
@end

@implementation A
-(void) say: (NSString*) s {
  printf( "say \"%s\"", [s UTF8String] );
}
-(NSMethodSignature*) methodSignatureForSelector: (SEL) aSelector {
  return [A instanceMethodSignatureForSelector: @selector(say:)];
}
-(void) forwardInvocation: (NSInvocation*) invocation {
  // [invocation setSelector:@selector(say:)];
  [invocation invokeWithTarget:self];
}
@end

int main(int args, char* argv[]){
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  A* myObject = [[[A alloc] init] autorelease];

  [myObject tryToSay:@"Hello strange method!"];

  [pool release];
  return 0;
}

I want to use -say: no matter which method is attempted used on objects of the class A.

The result is a Segfault.
It seems the invocation object sent to forwardInvocation still has @selector(tryToSay:) as its selector. Is it not supposed to get the same selector that was set in methodSignatureForSelector?


问:
Spotbugs-filter classname-suffix
If you create a filter XML-file for spotbugs like this

```<code>  <?xml version="1.0" encoding="UTF-8"?>
  <FindBugsFilter xmlns="https://github.com/spotbugs/filter/3.0. ...">
   <Match><Class name="de.test.Test.ClassASuffix" /></Match>
  </FindBugsFilter>
</code>```

it works perfectly for java-class ClassASuffix.
But it's tedious to add more rules like

```<code> <Match><Class name="de.test.Test.ClassASuffix" /></Match>
 <Match><Class name="de.test.Test.ClassBSuffix" /></Match>
 <Match><Class name="de.test.Test.ClassCSuffix" /></Match>
</code>```

How can you filter out all classes with *Suffix ?

I've already tried some of these examples. (like .*Test") But it just doesn't work.

答:
This works:</p>

```<code><Match><Class name="~.*?Suffix.*" /></Match>
</code>```

Title: Spotbugs-filter classname-suffix

Body:
If you create a filter XML-file for spotbugs like this

  <?xml version="1.0" encoding="UTF-8"?>
  <FindBugsFilter xmlns="https://github.com/spotbugs/filter/3.0. ...">
   <Match><Class name="de.test.Test.ClassASuffix" /></Match>
  </FindBugsFilter>

it works perfectly for java-class ClassASuffix.
But it's tedious to add more rules like

 <Match><Class name="de.test.Test.ClassASuffix" /></Match>
 <Match><Class name="de.test.Test.ClassBSuffix" /></Match>
 <Match><Class name="de.test.Test.ClassCSuffix" /></Match>

How can you filter out all classes with *Suffix ?

I've already tried some of these examples. (like .*Test") But it just doesn't work.

Body:
This works:

<Match><Class name="~.*?Suffix.*" /></Match>


问:
Display a message in Kendo MVC grid when no results are displayed
I need to display a friendly error message in the main Kendo grid area, instead of displaying a blank content area.

This is similar to this question but I am using Kendo MVC, and as Telerik's help reports: "NoRecordsTemplate is not available in Kendo UI Grid for ASP.NET MVC"

I’m providing the solution I came up with as an answer (which is similar to one on the other question). I’m not quite satisfied with the solution, as it’s hard to customize the error message.

答:
In the newest version of the Telerik controls you can simply place a string in the .NoRecords() helper function.  I'm currently on version 2017.2.621

```<code>@(Html.Kendo().Grid<YourModel>()
.Name("grid")
.NoRecords("No Records Found.")
</code>```

Body:
In the newest version of the Telerik controls you can simply place a string in the .NoRecords() helper function.  I'm currently on version 2017.2.621

@(Html.Kendo().Grid<YourModel>()
.Name("grid")
.NoRecords("No Records Found.")


问:
How do I run a function over and over by using parameters?
My case:

```<code>function randomLetter(){
    var random = letter[Math.floor(Math.random()*26)];
    return random;
}

function randomWord(wordLength){
    var random = randomLetter() + randomLetter() + randomLetter();
    return random;
}
</code>```

How do I write a code that run the randomLetter() function x times using parametes.

Example: I write 3 in the parameter, and the function will give me three random letters.

So instead of writing randomLetter() + randomLetter() + randomLetter(), I will just write randomWord(3), and I will get three random letters.

答:
Yet another recursive solution:

function randomLetter() {
  return ('qwertyuiopasdfghjklzxcvbnm')[Math.floor(Math.random()*26)];
}

function randomWord(wordLength) {
  return (wordLength > 0) ? (randomWord(wordLength - 1) + randomLetter()) : '';
}

console.log( randomWord(10) );```

Body:
My case:

function randomLetter(){
    var random = letter[Math.floor(Math.random()*26)];
    return random;
}

function randomWord(wordLength){
    var random = randomLetter() + randomLetter() + randomLetter();
    return random;
}

How do I write a code that run the randomLetter() function x times using parametes.

Example: I write 3 in the parameter, and the function will give me three random letters.

So instead of writing randomLetter() + randomLetter() + randomLetter(), I will just write randomWord(3), and I will get three random letters.


问:
Cache.properties (The system cannot find the file specified)
I just started using Android Studio 1.3 sdk 24 and it has worked fine until today. I get this error message about cache.properties and I delete that cache file but now I am getting this error message:

Error:C:\Users\user1.gradle\caches\2.4\scripts\asLocalRepo15_dhjxrnvsgiyg1ow3dfj4myl7\InitScript\initscript\cache.properties (The system cannot find the file specified)

I try file/invalidate caches/restart.. and rebuild project but am still getting this error message. How do I fix it?

答: Go to the folder indicated in the error message. Delete the cache.properties.lock file.</p>


问:
Can not take a full page screenshot in Applitools C#
I'm trying to take a full screen screenshot of my page by using this code:

```<code>public void OpenEyesForVisualTesting(string testName) {
 this.seleniumDriver.Driver = this.eyes.Open(this.seleniumDriver.Driver, "Zinc", testName);

}

public void CheckScreenForVisualTesting() {
 this.eyes.Check("Zinc", Applitools.Selenium.Target.Window().Fully());
}

public void CloseEyes() {
 this.eyes.close();
}
</code>```

but instead I just get a half a page of the screenshot, I tried to contact Applitools but they just told me to replace eyes.checkwindow() to eyes.Check("tag", Target.Window().Fully()); which still didn't work.

If anyone can help me that would be great.

答:
Use extent Reporting library, in that you can take screen shot as well as an interactive report on pass and fail cases.
here is the link how it works:
http://www.softwaretestingmaterial.com/generate-extent-reports/</p>

Body:
I'm trying to take a full screen screenshot of my page by using this code:

public void OpenEyesForVisualTesting(string testName) {
 this.seleniumDriver.Driver = this.eyes.Open(this.seleniumDriver.Driver, "Zinc", testName);

}

public void CheckScreenForVisualTesting() {
 this.eyes.Check("Zinc", Applitools.Selenium.Target.Window().Fully());
}

public void CloseEyes() {
 this.eyes.close();
}

but instead I just get a half a page of the screenshot, I tried to contact Applitools but they just told me to replace eyes.checkwindow() to eyes.Check("tag", Target.Window().Fully()); which still didn't work.

If anyone can help me that would be great.


Title: I am trying to pivot a file using awk

Body:
I am trying to pivot a file using awk.
Input File:

FA-1D_005   10000090fa180e49
FA-2D_006   10000090fa180e49
FA-2D_011   10000090fa180e49
FA-3D_004   10000090fa180e49
FA-4D_005   10000090fa180e49
FA-2D_004   20010090fa180e49
FA-2D_008   20010090fa180e49
FA-3D_004   20010090fa180e49
FA-1D_006   20020090fa180e49
FA-4D_004   20020090fa180e49
FA-1D_006   20030090fa180e49
FA-4D_004   20030090fa180e49
FA-2D_006   20040090fa180e49
FA-2D_009   20040090fa180e49
FA-3D_005   20040090fa180e49
FA-1D_006   10000090fa180e48
FA-1D_011   10000090fa180e48
FA-2D_006   10000090fa180e48
FA-3D_005   10000090fa180e48
FA-4D_006   10000090fa180e48
FA-1D_004   20010090fa180e48
FA-2D_006   20010090fa180e48
FA-2D_011   20010090fa180e48
FA-3D_004   20010090fa180e48
FA-3D_006   20010090fa180e48
FA-4D_005   20010090fa180e48
FA-1D_006   20020090fa180e48
FA-2D_004   20020090fa180e48
FA-2D_010   20020090fa180e48
FA-3D_004   20020090fa180e48
FA-4D_004   20020090fa180e48
FA-3D_005   20030090fa180e48
FA-3D_007   20030090fa180e48
FA-1D_005   20040090fa180e48

Desired output

FA-1D_005   10000090fa180e49
FA-2D_006

FA-2D_011

FA-3D_004

FA-4D_005

FA-2D_004   20010090fa180e49
FA-2D_008

FA-3D_004

FA-1D_006   20020090fa180e49

FA-4D_004

FA-1D_006   20030090fa180e49

FA-4D_004

FA-2D_006   20040090fa180e49
FA-2D_009

FA-3D_005

FA-1D_006   10000090fa180e48
FA-1D_011

FA-2D_006

FA-3D_005

FA-4D_006

FA-1D_004   20010090fa180e48
FA-2D_006

FA-2D_011

FA-3D_004

FA-3D_006

FA-4D_005

FA-1D_006   20020090fa180e48
FA-2D_004

FA-2D_010

FA-3D_004

FA-4D_004

FA-3D_005   20030090fa180e48

FA-3D_007

FA-1D_005   20040090fa180e48

Kindly let know which is the best approach to generate a pivot table?
Thanks in advance.

Body:
awk to the rescue!

$ awk 'NR==1{hr=sprintf("%"length($0)"s"," ");gsub(" ","-",hr)}
            {print (p==$2?$1:hr "\n" $0); p=$2}
         END{print hr}' file

---------------------------
FA-1D_005  10000090fa180e49
FA-2D_006
FA-2D_011
FA-3D_004
FA-4D_005
---------------------------
FA-2D_004  20010090fa180e49
FA-2D_008
FA-3D_004
---------------------------
FA-1D_006  20020090fa180e49
FA-4D_004
---------------------------
FA-1D_006  20030090fa180e49
FA-4D_004
---------------------------
FA-2D_006  20040090fa180e49
FA-2D_009
FA-3D_005
---------------------------
FA-1D_006  10000090fa180e48
FA-1D_011
FA-2D_006
FA-3D_005
FA-4D_006
---------------------------
FA-1D_004  20010090fa180e48
FA-2D_006
FA-2D_011
FA-3D_004
FA-3D_006
FA-4D_005
---------------------------
FA-1D_006  20020090fa180e48
FA-2D_004
FA-2D_010
FA-3D_004
FA-4D_004
---------------------------
FA-3D_005  20030090fa180e48
FA-3D_007
---------------------------
FA-1D_005  20040090fa180e48
---------------------------


问:
Angular 2 *ngIf not reevaluation on model change
I have a navbar with 2 buttons. I wish to only show the button for the other page and disable the button for the current page.

On opening the settings page, the settings button is hidden. When I click the profile button, it doesn't disable and settings button doesn't appear.

Here's the component class code:

export class SettingsComponent implements OnInit {
   isSettingsProfile = false;
   isSettingsHome = false;

   ngOnInit() {
       this.isSettingsHome = true;
       this.isSettingsProfile = false;
   }

   OnNavBarClick(button: string) {
       if (button = "settings") {
           console.log ('setting home true/ profile false')
           this.isSettingsHome = true;
           this.isSettingsProfile = false;
       }
       else if (button = "profiles") {
           console.log ('setting home false/ profile true')
           this.isSettingsProfile = true;
           this.isSettingsHome = false;
       }

   }```
</div>
</div>
</p>

<p>And the navbar html:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>        <ul class="nav navbar-nav navbar-right">
            <li> Home</li>
            <li *ngIf="!isSettingsHome" class="active">Settings</li>
            <li *ngIf="!isSettingsProfile">Profile</li>
        </ul></code>```

Any suggestions?

答:
I'm not sure what's going on here, and can't be without knowing more about your router structure, but I think gunter is likely correct that the navigation is causing the component to reload and thus reverting the component to it's initial state.  I will recommend the following restructure:

First, add the routerLinkActive directive to your router links and set the class to "hide-link" (or whatever name you prefer)

```<code> <li><a [routerLink]="['/settings']" routerLinkActive="hide-link">Settings</a></li>
</code>```

then define a simple CSS class to hide the link

```<code>.hide-link { display: none; }
</code>```

Body:
I have a navbar with 2 buttons. I wish to only show the button for the other page and disable the button for the current page.

On opening the settings page, the settings button is hidden. When I click the profile button, it doesn't disable and settings button doesn't appear.

Here's the component class code:

export class SettingsComponent implements OnInit {
   isSettingsProfile = false;
   isSettingsHome = false;

   ngOnInit() {
       this.isSettingsHome = true;
       this.isSettingsProfile = false;
   }

   OnNavBarClick(button: string) {
       if (button = "settings") {
           console.log ('setting home true/ profile false')
           this.isSettingsHome = true;
           this.isSettingsProfile = false;
       }
       else if (button = "profiles") {
           console.log ('setting home false/ profile true')
           this.isSettingsProfile = true;
           this.isSettingsHome = false;
       }

   }

And the navbar html:

 Home

Settings

Profile

Any suggestions?

Body:
I'm not sure what's going on here, and can't be without knowing more about your router structure, but I think gunter is likely correct that the navigation is causing the component to reload and thus reverting the component to it's initial state.  I will recommend the following restructure:

First, add the routerLinkActive directive to your router links and set the class to "hide-link" (or whatever name you prefer)

 <li><a [routerLink]="['/settings']" routerLinkActive="hide-link">Settings</a></li>

then define a simple CSS class to hide the link

.hide-link { display: none; }


问:
How to save an image from ds9 as a region file to use it some other time?
I'm trying to save a ds9 image as a region file but after I saved it I can't open it using ds9.here is how I did it:regions,save regions,then ok(format=ds9 and coordinate system fk5). where is the problem?any help please?Or any system may be using the command line is welcome.</p>

答:
I ran into this as well. Silly trick but even though the save as file type defaults to .reg, you have to actually type in ".reg" at the end of the file name.

So do what you've been doing ,regions-> save regions-> etc etc. then just add in .reg at the end of the filename you pick.


问:
Need to Run a vbscipt via Batch file in Silent mode
I know this is a duplicate. But I am stuck and not able to understand those properly.

The first vbs file:

```<code>Msgbox "Success"
</code>```

The Bat File:

```<code>@echo off
Start "C:\Success.vbs" %*
</code>```

I need to run the bat file in silent mode. Could anyone explain me how i can do that.

答:
Create another VBS file as a wrapper:

```<code>Dim Shell
Set Shell = CreateObject("WScript.Shell")
Shell.Run "C:\Whatever.bat", 0
</code>```

Now run this VBS file, your batch will be executed without showing a "blackboard".

Body:
I know this is a duplicate. But I am stuck and not able to understand those properly.

The first vbs file:

Msgbox "Success"

The Bat File:

@echo off
Start "C:\Success.vbs" %*

I need to run the bat file in silent mode. Could anyone explain me how i can do that.

Body:
Create another VBS file as a wrapper:

Dim Shell
Set Shell = CreateObject("WScript.Shell")
Shell.Run "C:\Whatever.bat", 0

Now run this VBS file, your batch will be executed without showing a "blackboard".


问:
How to derive the equation of a density distribution in SAS?
I am using the following procedure to get the density plot of transaction counts:

```<code>PROC SGPLOT DATA = Tran_Restaurant ;
  density Transaction_Count/ scale=density ;
  "Restaurant Transaction Count";
  XAXIS LABEL = 'Transaction_Count' GRID VALUES = (0 TO 100 BY 10);
RUN;
</code>```

Sample Data:

```<code>Customer_ID   Transaction_Count
1213x         23
2131x         14
</code>```

Customer_ID is distinct in the data set.
So, from the plot for each transaction_count we can get the number of customers.

I wanted to get the equation of the density curve? Is it possible to do that in SAS?

答:
That statement is estimating a normal density curve to your discrete data.  A normal density has 2 parameters, mean and standard deviation.  You can get that from PROC MEANS.

```<code>proc means data=Tran_Restaurant mean std;
var Transaction_Count;
run;
</code>```

Now you have an issue of discrete count values and a continuous distribution.  Multiple ways of doing this, none is perfect.

One way is to get the probability of being in a range around a given number. Because your numbers are integers, you could use a +/- 0.5.  Put another way

```<code>P(x | V-0.5 <= x <= V+0.5)
</code>```

For a normal distribution using the SAS CDF function:

```<code>P = CDF('normal',V+.5,mean,std) - CDF('normal',V-.5,mean,std)
</code>```

So if your data has 100 observations, then you would expect

```<code>E_count = P*100;
</code>```

Body:
I am using the following procedure to get the density plot of transaction counts:

PROC SGPLOT DATA = Tran_Restaurant ;
  density Transaction_Count/ scale=density ;
  "Restaurant Transaction Count";
  XAXIS LABEL = 'Transaction_Count' GRID VALUES = (0 TO 100 BY 10);
RUN;

Sample Data:

Customer_ID   Transaction_Count
1213x         23
2131x         14

Customer_ID is distinct in the data set.
So, from the plot for each transaction_count we can get the number of customers.

I wanted to get the equation of the density curve? Is it possible to do that in SAS?

Body:
That statement is estimating a normal density curve to your discrete data.  A normal density has 2 parameters, mean and standard deviation.  You can get that from PROC MEANS.

proc means data=Tran_Restaurant mean std;
var Transaction_Count;
run;

Now you have an issue of discrete count values and a continuous distribution.  Multiple ways of doing this, none is perfect.

One way is to get the probability of being in a range around a given number. Because your numbers are integers, you could use a +/- 0.5.  Put another way

P(x | V-0.5 <= x <= V+0.5)

For a normal distribution using the SAS CDF function:

P = CDF('normal',V+.5,mean,std) - CDF('normal',V-.5,mean,std)

So if your data has 100 observations, then you would expect

E_count = P*100;


问:
php - Convert array to an array
I have an array like below:

```<code>array:3 [▼
  "_token" => "hLuF5TLimRRkxRUOeeWoOby7iXLNXU7EiHRmTAso"
  "room_id" => array:3 [▼
    0 => "089a6ca8-26de-3ca2-bbbf-17c410d15266"
    1 => "13c56ac2-6c77-3ca7-b24a-2a70f4f0526c"
    2 => "2d9b7392-aa50-37e4-882a-804affb87223"
  ]
  "new_electric" => array:3 [▼
    0 => "123"
    1 => "234"
    2 => "345"
  ]
]
</code>```

How can I slice it into new array which like

```<code>array:4 [▼
  "_token" => "hLuF5TLimRRkxRUOeeWoOby7iXLNXU7EiHRmTAso"
  "1" => array:2 [▼
    "room_d" => "089a6ca8-26de-3ca2-bbbf-17c410d15266"
    "new_electric => "123"
  ]
  "2" => array:2 [▼
    "room_id" => "13c56ac2-6c77-3ca7-b24a-2a70f4f0526c"
    "new_electric" => "234"
  ]
  "3" => array:2 [▼
    "room_id" => "2d9b7392-aa50-37e4-882a-804affb87223"
    "new_electric" => "345"
      ]
]
</code>```

I think I need to use an array_push but I don't know how to do that ? Please help.

答:
You have to use foreach

```<code>$arr = array(
      "_token" => "hLuF5TLimRRkxRUOeeWoOby7iXLNXU7EiHRmTAso",
      "room_id" => array(
        0 => "089a6ca8-26de-3ca2-bbbf-17c410d15266",
        1 => "13c56ac2-6c77-3ca7-b24a-2a70f4f0526c",
        2 => "2d9b7392-aa50-37e4-882a-804affb87223",
      ),
      "new_electric" => array(
        0 => "123",
        1 => "234",
        2 => "345",
      )
    );

    $final = array();
    $final[ "_token" ] = $arr[ "_token" ];

    foreach( $arr[ "room_id" ] as $key => $value ) {

        $final[ ( $key + 1 ) ] = array(
            "room_id" => $value,
            "new_electric" => $arr[ "new_electric" ][ $key ]
        );

    }
</code>```

This will result to:

```<code>   Array
(
    [_token] => hLuF5TLimRRkxRUOeeWoOby7iXLNXU7EiHRmTAso
    [1] => Array
        (
            [room_id] => 089a6ca8-26de-3ca2-bbbf-17c410d15266
            [new_electric] => 123
        )

    [2] => Array
        (
            [room_id] => 13c56ac2-6c77-3ca7-b24a-2a70f4f0526c
            [new_electric] => 234
        )

    [3] => Array
        (
            [room_id] => 2d9b7392-aa50-37e4-882a-804affb87223
            [new_electric] => 345
        )

)
</code>```

Note: Use $key + 1 because you want the index to start from 1

Title: php - Convert array to an array

Body:
I have an array like below:

array:3 [▼
  "_token" => "hLuF5TLimRRkxRUOeeWoOby7iXLNXU7EiHRmTAso"
  "room_id" => array:3 [▼
    0 => "089a6ca8-26de-3ca2-bbbf-17c410d15266"
    1 => "13c56ac2-6c77-3ca7-b24a-2a70f4f0526c"
    2 => "2d9b7392-aa50-37e4-882a-804affb87223"
  ]
  "new_electric" => array:3 [▼
    0 => "123"
    1 => "234"
    2 => "345"
  ]
]

How can I slice it into new array which like

array:4 [▼
  "_token" => "hLuF5TLimRRkxRUOeeWoOby7iXLNXU7EiHRmTAso"
  "1" => array:2 [▼
    "room_d" => "089a6ca8-26de-3ca2-bbbf-17c410d15266"
    "new_electric => "123"
  ]
  "2" => array:2 [▼
    "room_id" => "13c56ac2-6c77-3ca7-b24a-2a70f4f0526c"
    "new_electric" => "234"
  ]
  "3" => array:2 [▼
    "room_id" => "2d9b7392-aa50-37e4-882a-804affb87223"
    "new_electric" => "345"
      ]
]

I think I need to use an array_push but I don't know how to do that ? Please help.

Body:
You have to use foreach

$arr = array(
      "_token" => "hLuF5TLimRRkxRUOeeWoOby7iXLNXU7EiHRmTAso",
      "room_id" => array(
        0 => "089a6ca8-26de-3ca2-bbbf-17c410d15266",
        1 => "13c56ac2-6c77-3ca7-b24a-2a70f4f0526c",
        2 => "2d9b7392-aa50-37e4-882a-804affb87223",
      ),
      "new_electric" => array(
        0 => "123",
        1 => "234",
        2 => "345",
      )
    );

    $final = array();
    $final[ "_token" ] = $arr[ "_token" ];

    foreach( $arr[ "room_id" ] as $key => $value ) {

        $final[ ( $key + 1 ) ] = array(
            "room_id" => $value,
            "new_electric" => $arr[ "new_electric" ][ $key ]
        );

    }

This will result to:

   Array
(
    [_token] => hLuF5TLimRRkxRUOeeWoOby7iXLNXU7EiHRmTAso
    [1] => Array
        (
            [room_id] => 089a6ca8-26de-3ca2-bbbf-17c410d15266
            [new_electric] => 123
        )

    [2] => Array
        (
            [room_id] => 13c56ac2-6c77-3ca7-b24a-2a70f4f0526c
            [new_electric] => 234
        )

    [3] => Array
        (
            [room_id] => 2d9b7392-aa50-37e4-882a-804affb87223
            [new_electric] => 345
        )

)

Note: Use $key + 1 because you want the index to start from 1


问:
Posting json to the same page with fetch
im trying to achieve something pretty simple, i just wanna post the form to itself without a refresh, however i require it to post the data from the form as it is captured by the controller. im getting the data in the back end i just need the form to post successfully without a refresh and then show and hide certain things. Also, i get this error

Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

i presume this is why im not reaching my conditional

```<code>const wrappers = document.querySelectorAll('.form-wrapper');

if (wrappers) {
wrappers.forEach(function(el){
    const form = el.querySelector('.submit-form');
    let currentURL = window.location.href;
    const output = el.nextElementSibling;

    form.addEventListener('submit', function(e){
        const data = new FormData(form);
        fetch(`${currentURL}`, {
            credentials: 'include',
            method: 'POST',
            body: data,
        })
        .then((res) => res.json())
        .then((res) => {
            if (res.success) {
                console.log('submitted');
                output.classList.remove('none');
                form.classList.add('none');
            }
            else if (res.error) {
                console.log('Error: ' + res.error);
            }
        });
        e.preventDefault();
    },false);
});
}
</code>```

答:
Use preventDefault from the event object towards the beginning of your block:

```<code>form.addEventListener('submit', function(e) {
  e.preventDefault();
  ...
}
</code>```

In the event that your POST request wasn't successful, supply a catch block:

```<code>fetch(`${currentURL}`, {
  credentials: 'include',
  method: 'POST',
  body: data,
})
.catch(err => console.log(err));
</code>```

Body:
im trying to achieve something pretty simple, i just wanna post the form to itself without a refresh, however i require it to post the data from the form as it is captured by the controller. im getting the data in the back end i just need the form to post successfully without a refresh and then show and hide certain things. Also, i get this error

Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

i presume this is why im not reaching my conditional

const wrappers = document.querySelectorAll('.form-wrapper');

if (wrappers) {
wrappers.forEach(function(el){
    const form = el.querySelector('.submit-form');
    let currentURL = window.location.href;
    const output = el.nextElementSibling;

    form.addEventListener('submit', function(e){
        const data = new FormData(form);
        fetch(`${currentURL}`, {
            credentials: 'include',
            method: 'POST',
            body: data,
        })
        .then((res) => res.json())
        .then((res) => {
            if (res.success) {
                console.log('submitted');
                output.classList.remove('none');
                form.classList.add('none');
            }
            else if (res.error) {
                console.log('Error: ' + res.error);
            }
        });
        e.preventDefault();
    },false);
});
}

Body:
Use preventDefault from the event object towards the beginning of your block:

form.addEventListener('submit', function(e) {
  e.preventDefault();
  ...
}

In the event that your POST request wasn't successful, supply a catch block:

fetch(`${currentURL}`, {
  credentials: 'include',
  method: 'POST',
  body: data,
})
.catch(err => console.log(err));


问:
Disable option if used in another drop menu
I have researched some information regarding the best way to tackle my problem and have found this thread - - Stackoverflow link but I am unsure how to add it to my existing Fiddle.

I have 3 dropmenus (total 9) that use the same array (specialList) to populate it.

What I want to do for the 3 ng-model named "special1, special2 and special3" is if they select an item, in either of the 3 menus, it will be disabled on the other 2.

I think I need a blank array to push values into.

I can't figure a way to do it on mine using the link above.

This is my fiddle

```<code>var app = angular.module('app', []);
////////////////////////////////////////////////
var clipboard = new Clipboard('.btn');

var platformList = [
        {id:'aa', power: 3700, level: 'level 1', picture: 1, armourPoints: 400},

        {id:'ab', power: 3700, level: 'level 2', picture: 2, armourPoints: 1200},

        {id:'ac', power: 3700, level: 'level 3', picture: 3, armourPoints: 3600},

        {id:'ad', power: 3700, level: 'level 4', picture: 4, armourPoints: 10800},

        {id:'ae', power: 4000, level: 'level 5', picture: 5, armourPoints: 14400},

        {id:'af', power: 6400, level: 'level 6', picture: 6, armourPoints: 57600},

        {id:'ag', power: 8155, level: 'level 7', picture: 7, armourPoints: 280000},

        {id:'ah', power: 16310, level: 'level 8', picture: 8, armourPoints: 1200000, explosiveDamage:20, ballisticDefence:30, explosiveDefence:30, penetratingDefence:30, radioactiveDefence:30},

        {id:'ai', power: 32620, level: 'level 9', picture: 9, armourPoints: 3300000, explosiveDamage:20, ballisticDefence:50, explosiveDefence:50, penetratingDefence:50, radioactiveDefence:50, corrosiveDefence: 50, concussiveDefence: 50}
        ];
///////////////
var weaponList = [
        {id:'ba', power:0, name:' None'},

        {id:'bb', name:'Phlogiston Launcher', power:8600, weaponType:'Radioactive', damageType:'Launcher', projectileSpeed:300, accuracy:90, range:200, launcherDamage:17000, salvo:5, reload:5, shockwave:25000, special: [{resonanceTrigger:'yes'},{affects:'Mortar'},{firefieldchance:20},{duration:4},{abiltyRange:24},{radField:-300}]},

                {id:'bc', name:'Venom Spitter', power:8900, weaponType:'Scatter Gun', damageType:'Corrosive', corrosiveBypass:95, corrosiveDamage:22400, multishot:7, projectileSpeed:330, range:105, reload:6.8, splash:16, submersedDamage:22400},

                {id:'bd', name:'Explosive D99-S', power:8900, weaponType:'Rocket', damageType:'Explosive', explosiveDamage:30000, explosiveBypass:95, projectileSpeed:330, range:105, reload:11.25, salvo:3, splash:20, spread:80, submersedDamage:30000},

                {id:'be', name:'Basilisk', power:2580, weaponType:'Scatter Gun', damageType:'Corrosive', corrosiveBypass:100, corrosiveDamage:10000, multishot:10, projectileSpeed:650, range:105, reload:3, splash:12.4, spread:100, submersedDamage:10000},

                {id:'bf', name:'Sentinel 5', power:967, weaponType:'Missile', damageType:'Penetrating', accuracy:100, ballisticDamage:125, penetratingDamage:1287, projectileSpeed:110, range:105, reload:5, salvo:4, flakEvasion:40},

                {id:'bg', name:'Hyena', power:8800, weaponType:'Missile', damageType:'Penetrating', accuracy:75, penetratingDamage:39986, penetrativeBypass:100, projectileSpeed:160, range:105, reload:5, flakEvasion:40},

                {id:'bh', name:'Apocalypse Mortar', power:3420, weaponType:'Mortar', damageType:'Explosive', explosiveDamage:7276, explosiveBypass:100, projectileSpeed:60, range:160, reload:12.11, salvo:4, splash:30, spread:80},

                {id:'bi', name:'Axiom' , power:8600, weaponType:'Depth Charge' , damageType:'Concussive' , concussiveBypass:90, concussiveDamage:51000, projectileSpeed:1000, range:235, reload:20, salvo:5, splash:20, spread:10, submersedDamage:51000, special:[{windupReload:4900},{reloadDecay:    4},{'maxReload':490}]},

        ];
///////////////
var armourList = [
        {id:'ia', power: 0, name: ' None'},
                {id:'ib' , name:'Solar Reinforcements', armourPoints:15000, baseMaxPower:50},
        {id:'ic', power: 2000, name:'name2', bal: 1000},
        {id:'id', power: 3000, name:'name3', conc: 2500},
        {id:'ie', power: 4000, name:'name4', conc: 5000}
        ];
///////////////
var specialList = [
        {id:'pa', power: 0, name: ' None'},
        {id:'pb', name:'Fire Support Platform M', weaponPower:33, penetratingdamage:31, penetratingrange:25},

                {id:'pc', name:'SSKP Enhancement', weaponPower:13, penetratingAccuracy:50},

                {id:'pd', name:'Thermobaric Casing 2', weaponPower:7,penetratingDamage:27},

                {id:'pe', name:'Supercharged EM Rails 2', weaponPower:45, ballisticCriticalChance:25, ballisticCriticalDamage:300},

                {id:'pf', name:'Ballistic Recoil Suppressor', weaponPower:20, ballisticDamage:65, ballisticReload:30},

        {id:'pg', name:'Compound Panels E', armourPower:12, ballisticDefence:33, explosiveDefence:33, penetratingDefence:33},

        ];

///////////////
var transformersList = [
        {id:'wa', power: 0, name: ' None'},

        {id:'wb' , name:'A-T Transformer 1', weaponPower:25, bonusDamage:35, ballisticDefence:-10, explosiveDefence:-10, penetratingDefence:-10, radioactiveDefence:-10, armourAbilities:-10},

        {id:'wc', power: 20000, name:'name2', bal: 1000},
        {id:'wd', power: 30000, name:'name3', conc: 2500},
        {id:'we', power: 40000, name:'name4', conc: 5000}
        ];
///////////////

///////////////////////////////////////////////
function Ctrl($scope) {
    $scope.lists = {

    platform:   platformList,
            weapon:     weaponList,
     special:   specialList,
      armour:   armourList,
       trans:   transformersList,
                                    };
////////////////////////////////////////////////
Object.assign($scope, {
       platform: '',
       weapon: '',
       armour1: '',
       armour2: '',
       armour3: '',
       special1: '',
       special2: '',
       special3: '',
       trans1: '',

});
////////////////////////////////////////////////
//var checkURL = $(location).attr("href") //use this line for live site as it will use the URL
//var domain = checkURL.split('&');         //use this line for live site as it will split the URL

var fiddleURL = '   http://www.ahoymearty.co.uk/waynestest/turretbuilder/index.html#&ah&bq&ib&ib&ib&pe&pf&pg&wb' //temp URL for testing - delete this line on live site
var domain = fiddleURL.split('&');      //temp URL split for JSFiddle testing

var platformID = domain[1];
var weaponID = domain[2];
var armour1ID = domain[3];
var armour2ID = domain[4];
var armour3ID = domain[5];
var special1ID = domain[6];
var special2ID = domain[7];
var special3ID = domain[8];
var trans1ID = domain[9];

var platformFromURL = _.max(platformList, function(searchPlatform){ return searchPlatform.id == platformID;});
var weaponFromURL = _.max(weaponList, function(searchWeapon){ return searchWeapon.id == weaponID;});
var armour1FromURL = _.max(armourList, function(searchArmour1){ return searchArmour1.id == armour1ID;});
var armour2FromURL = _.max(armourList, function(searchArmour2){ return searchArmour2.id == armour2ID;});
var armour3FromURL = _.max(armourList, function(searchArmour3){ return searchArmour3.id == armour3ID;});
var special1FromURL = _.max(specialList, function(searchSpecial1){ return searchSpecial1.id == special1ID;});
var special2FromURL = _.max(specialList, function(searchSpecial2){ return searchSpecial2.id == special2ID;});
var special3FromURL = _.max(specialList, function(searchSpecial3){ return searchSpecial3.id == special3ID;});
var trans1FromURL = _.max(transformersList, function(searchTrans1){ return searchTrans1.id == trans1ID;});

$scope.platform = platformFromURL;
$scope.weapon = weaponFromURL;
$scope.armour1 = armour1FromURL;
$scope.armour2 = armour2FromURL;
$scope.armour3 = armour3FromURL;
$scope.special1 = special1FromURL;
$scope.special2 = special2FromURL;
$scope.special3 = special3FromURL;
$scope.trans1 = trans1FromURL;

////////////////////////////////////////////////
$scope.calcTotals = function(codeAddress){
//////////////////////////////////////////////////
//               Base Power Stats               //
//////////////////////////////////////////////////
     $scope.powertotal = Math.round(
     ($scope.weapon.power || 0) +
     ($scope.special1.power || 0) +
     ($scope.special2.power || 0) +
     ($scope.special3.power || 0) +
     ($scope.armour1.power || 0) +
     ($scope.armour2.power || 0) +
     ($scope.armour3.power || 0) +
     ($scope.trans1.power || 0) +
     (($scope.trans1.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.special1.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.special2.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.special3.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.armour1.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.armour2.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.armour3.weaponPower/100) * $scope.weapon.power || 0)
                                                                );
//////////////////////////////////////////////////
//                 Attack Stats                 //
//////////////////////////////////////////////////
$scope.ballisticDamageTotal = Math.round(
            ($scope.weapon.ballisticDamage || 0) +
        (($scope.special1.ballisticDamage/100) * $scope.weapon.ballisticDamage || 0) +
      (($scope.special2.ballisticDamage/100) * $scope.weapon.ballisticDamage || 0) +
      (($scope.special3.ballisticDamage/100) * $scope.weapon.ballisticDamage || 0)
                                                                        );
////////////////////////////////////
$scope.damageTotal = Math.floor(
                $scope.ballisticDamageTotal +
        (($scope.trans1.bonusDamage/100) * $scope.ballisticDamageTotal || 0)
                                                                );
////////////////////////////////////
$scope.ballisticReloadPercent = Math.floor(
            ($scope.special1.ballisticReload ||0) +
      ($scope.special2.ballisticReload ||0) +
      ($scope.special3.ballisticReload ||0)
                                                                );
////////////////////////////////////
$scope.ballisticDamagePercent = Math.floor(
            ($scope.special1.ballisticDamage ||0) +
      ($scope.special2.ballisticDamage ||0) +
      ($scope.special3.ballisticDamage ||0)
                                                                );
////////////////////////////////////////////////
$scope.explosiveDamagePercent = Math.floor(
            ($scope.special1.explosiveDamage ||0) +
      ($scope.special2.explosiveDamage ||0) +
      ($scope.special3.explosiveDamage ||0)
                                                                );
////////////////////////////////////////////////
$scope.ballisticCriticalChanceTotal = Math.floor(
            ($scope.special1.ballisticCriticalChance ||0) +
      ($scope.special2.ballisticCriticalChance||0)  +
      ($scope.special3.ballisticCriticalChance ||0)
                                                                );
////////////////////////////////////////////////
$scope.ballisticCriticalDamageTotal = Math.floor(
            ($scope.special1.ballisticCriticalDamage ||0) +
      ($scope.special2.ballisticCriticalDamage||0)  +
      ($scope.special3.ballisticCriticalDamage ||0)
                                                                );
////////////////////////////////////////////////

//////////////////////////////////////////////////
//                 Defence Stats                //
//////////////////////////////////////////////////

var balisticDefence1 = ($scope.platform.ballisticDefence) ||0
var balisticDefence2 = (100-(balisticDefence1)) * ($scope.special1.ballisticDefence / 100) ||0
var balisticDefence3 = (100-(balisticDefence1 + balisticDefence2)) * ($scope.special2.ballisticDefence / 100) ||0
var balisticDefence4 = (100-(balisticDefence1 + balisticDefence2 + balisticDefence3)) * ($scope.special3.ballisticDefence / 100) ||0
var balisticDefence5 = (100-(balisticDefence1 + balisticDefence2 + balisticDefence3 + balisticDefence4)) * ($scope.trans1.ballisticDefence / 100) ||0
//////////////////////////////////////////////////
var explosiveDefence1 = ($scope.platform.explosiveDefence) ||0
var explosiveDefence2 = (100-(balisticDefence1)) * ($scope.special1.explosiveDefence / 100) ||0
var explosiveDefence3 = (100-(balisticDefence1 + balisticDefence2)) * ($scope.special2.explosiveDefence / 100) ||0
var explosiveDefence4 = (100-(balisticDefence1 + balisticDefence2 + balisticDefence3)) * ($scope.special3.explosiveDefence / 100) ||0
var explosiveDefence5 = (100-(balisticDefence1 + balisticDefence2 + balisticDefence3 + balisticDefence4)) * ($scope.trans1.explosiveDefence / 100) ||0
//////////////////////////////////////////////////
var penetratingDefence1 = ($scope.platform.penetratingDefence) ||0
var penetratingDefence2 = (100-(penetratingDefence1)) * ($scope.special1.penetratingDefence / 100) ||0
var penetratingDefence3 = (100-(penetratingDefence1 + penetratingDefence2)) * ($scope.special2.explosiveDefence / 100) ||0
var penetratingDefence4 = (100-(penetratingDefence1 + penetratingDefence2 + penetratingDefence3)) * ($scope.special3.penetratingDefence / 100) ||0
var penetratingDefence5 = (100-(penetratingDefence1 + penetratingDefence2 + penetratingDefence3 + penetratingDefence4)) * ($scope.trans1.penetratingDefence / 100) ||0
//////////////////////////////////////////////////
var radioactiveDefence1 = ($scope.platform.radioactiveDefence) ||0
var radioactiveDefence2 = (100-(radioactiveDefence1)) * ($scope.special1.radioactiveDefence / 100) ||0
var radioactiveDefence3 = (100-(radioactiveDefence1 + radioactiveDefence2)) * ($scope.special2.radioactiveDefence / 100) ||0
var radioactiveDefence4 = (100-(radioactiveDefence1 + radioactiveDefence2 + radioactiveDefence3)) * ($scope.special3.radioactiveDefence / 100) ||0
var radioactiveDefence5 = (100-(radioactiveDefence1 + radioactiveDefence2 + radioactiveDefence3 + radioactiveDefence4)) * ($scope.trans1.radioactiveDefence / 100) ||0
//////////////////////////////////////////////////
var corrosiveDefence1 = ($scope.platform.corrosiveDefence) ||0
var corrosiveDefence2 = (100-(corrosiveDefence1)) * ($scope.special1.corrosiveDefence / 100) ||0
var corrosiveDefence3 = (100-(corrosiveDefence1 + corrosiveDefence2)) * ($scope.special2.corrosiveDefence / 100) ||0
var corrosiveDefence4 = (100-(corrosiveDefence1 + corrosiveDefence2 + corrosiveDefence3)) * ($scope.special3.corrosiveDefence / 100) ||0
var corrosiveDefence5 = (100-(corrosiveDefence1 + corrosiveDefence2 + corrosiveDefence3 + corrosiveDefence4)) * ($scope.trans1.corrosiveDefence / 100) ||0
//////////////////////////////////////////////////
var concussiveDefence1 = ($scope.platform.concussiveDefence) ||0
var concussiveDefence2 = (100-(concussiveDefence1)) * ($scope.special1.concussiveDefence / 100) ||0
var concussiveDefence3 = (100-(concussiveDefence1 + concussiveDefence2)) * ($scope.special2.concussiveDefence / 100) ||0
var concussiveDefence4 = (100-(concussiveDefence1 + concussiveDefence2 + concussiveDefence3)) * ($scope.special3.concussiveDefence / 100) ||0
var concussiveDefence5 = (100-(concussiveDefence1 + concussiveDefence2 + concussiveDefence3 + concussiveDefence4)) * ($scope.trans1.concussiveDefence / 100) ||0
//////////////////////////////////////////////////

$scope.ballisticDefenceTotal = Math.round(balisticDefence1 + balisticDefence2 + balisticDefence3  + balisticDefence4 + balisticDefence5)
$scope.explosiveDefenceTotal = Math.round(explosiveDefence1 + explosiveDefence2 + explosiveDefence3  + explosiveDefence4 + explosiveDefence5)
$scope.penetratingDefenceTotal = Math.round(penetratingDefence1 + penetratingDefence2 + penetratingDefence3  + penetratingDefence4 + penetratingDefence5)
$scope.radioactiveDefenceTotal = Math.round(radioactiveDefence1 + radioactiveDefence2 + radioactiveDefence3  + radioactiveDefence4 + radioactiveDefence5)
$scope.corrosiveDefenceTotal = Math.round(corrosiveDefence1 + corrosiveDefence2 + corrosiveDefence3  + corrosiveDefence4 + corrosiveDefence5)
$scope.concussiveDefenceTotal = Math.round(concussiveDefence1 + concussiveDefence2 + concussiveDefence3  + concussiveDefence4 + concussiveDefence5)

//////////////////////////////////////////////////
$scope.armourPointsTotal = $scope.platform.armourPoints +
$scope.armour1.armourPoints  +
$scope.armour2.armourPoints +
$scope.armour3.armourPoints

//////////////////////////////////////////////////
//////////////////////////////////////////////////
var buildPower = $scope.powertotal;
var totalPower = $scope.platform.power + ($scope.armour1.baseMaxPower || 0) + ($scope.armour2.baseMaxPower || 0) + ($scope.armour3.baseMaxPower || 0) ;
var pictureNeeded = $scope.platform.picture;

//change image according to drop menu selection
var imageUrl = "http://ahoymearty.co.uk/turretbuilder/images/turretlvl" + pictureNeeded + ".png"
$('#platformImage').css('background-image', 'url(' + imageUrl + ')');

////////////////////////////////////////////////

} //end of var app
</code>```

答:
You can disable select drop down by using ng-disabled.
Check the following code and this revision of your code

```<code><select ng-show="platform.picture > 5" id="loadedspecial3" ng-model='special3' ng-options='value.name for value in lists.special | orderBy: "name"' ng-change='calcTotals()' ng-disabled="special1.name != ' None' || special2.name != ' None'"></select>`
</code>```

Body:
I have researched some information regarding the best way to tackle my problem and have found this thread - - Stackoverflow link but I am unsure how to add it to my existing Fiddle.

I have 3 dropmenus (total 9) that use the same array (specialList) to populate it.

What I want to do for the 3 ng-model named "special1, special2 and special3" is if they select an item, in either of the 3 menus, it will be disabled on the other 2.

I think I need a blank array to push values into.

I can't figure a way to do it on mine using the link above.

This is my fiddle

var app = angular.module('app', []);
////////////////////////////////////////////////
var clipboard = new Clipboard('.btn');

var platformList = [
        {id:'aa', power: 3700, level: 'level 1', picture: 1, armourPoints: 400},

        {id:'ab', power: 3700, level: 'level 2', picture: 2, armourPoints: 1200},

        {id:'ac', power: 3700, level: 'level 3', picture: 3, armourPoints: 3600},

        {id:'ad', power: 3700, level: 'level 4', picture: 4, armourPoints: 10800},

        {id:'ae', power: 4000, level: 'level 5', picture: 5, armourPoints: 14400},

        {id:'af', power: 6400, level: 'level 6', picture: 6, armourPoints: 57600},

        {id:'ag', power: 8155, level: 'level 7', picture: 7, armourPoints: 280000},

        {id:'ah', power: 16310, level: 'level 8', picture: 8, armourPoints: 1200000, explosiveDamage:20, ballisticDefence:30, explosiveDefence:30, penetratingDefence:30, radioactiveDefence:30},

        {id:'ai', power: 32620, level: 'level 9', picture: 9, armourPoints: 3300000, explosiveDamage:20, ballisticDefence:50, explosiveDefence:50, penetratingDefence:50, radioactiveDefence:50, corrosiveDefence: 50, concussiveDefence: 50}
        ];
///////////////
var weaponList = [
        {id:'ba', power:0, name:' None'},

        {id:'bb', name:'Phlogiston Launcher', power:8600, weaponType:'Radioactive', damageType:'Launcher', projectileSpeed:300, accuracy:90, range:200, launcherDamage:17000, salvo:5, reload:5, shockwave:25000, special: [{resonanceTrigger:'yes'},{affects:'Mortar'},{firefieldchance:20},{duration:4},{abiltyRange:24},{radField:-300}]},

                {id:'bc', name:'Venom Spitter', power:8900, weaponType:'Scatter Gun', damageType:'Corrosive', corrosiveBypass:95, corrosiveDamage:22400, multishot:7, projectileSpeed:330, range:105, reload:6.8, splash:16, submersedDamage:22400},

                {id:'bd', name:'Explosive D99-S', power:8900, weaponType:'Rocket', damageType:'Explosive', explosiveDamage:30000, explosiveBypass:95, projectileSpeed:330, range:105, reload:11.25, salvo:3, splash:20, spread:80, submersedDamage:30000},

                {id:'be', name:'Basilisk', power:2580, weaponType:'Scatter Gun', damageType:'Corrosive', corrosiveBypass:100, corrosiveDamage:10000, multishot:10, projectileSpeed:650, range:105, reload:3, splash:12.4, spread:100, submersedDamage:10000},

                {id:'bf', name:'Sentinel 5', power:967, weaponType:'Missile', damageType:'Penetrating', accuracy:100, ballisticDamage:125, penetratingDamage:1287, projectileSpeed:110, range:105, reload:5, salvo:4, flakEvasion:40},

                {id:'bg', name:'Hyena', power:8800, weaponType:'Missile', damageType:'Penetrating', accuracy:75, penetratingDamage:39986, penetrativeBypass:100, projectileSpeed:160, range:105, reload:5, flakEvasion:40},

                {id:'bh', name:'Apocalypse Mortar', power:3420, weaponType:'Mortar', damageType:'Explosive', explosiveDamage:7276, explosiveBypass:100, projectileSpeed:60, range:160, reload:12.11, salvo:4, splash:30, spread:80},

                {id:'bi', name:'Axiom' , power:8600, weaponType:'Depth Charge' , damageType:'Concussive' , concussiveBypass:90, concussiveDamage:51000, projectileSpeed:1000, range:235, reload:20, salvo:5, splash:20, spread:10, submersedDamage:51000, special:[{windupReload:4900},{reloadDecay:    4},{'maxReload':490}]},

        ];
///////////////
var armourList = [
        {id:'ia', power: 0, name: ' None'},
                {id:'ib' , name:'Solar Reinforcements', armourPoints:15000, baseMaxPower:50},
        {id:'ic', power: 2000, name:'name2', bal: 1000},
        {id:'id', power: 3000, name:'name3', conc: 2500},
        {id:'ie', power: 4000, name:'name4', conc: 5000}
        ];
///////////////
var specialList = [
        {id:'pa', power: 0, name: ' None'},
        {id:'pb', name:'Fire Support Platform M', weaponPower:33, penetratingdamage:31, penetratingrange:25},

                {id:'pc', name:'SSKP Enhancement', weaponPower:13, penetratingAccuracy:50},

                {id:'pd', name:'Thermobaric Casing 2', weaponPower:7,penetratingDamage:27},

                {id:'pe', name:'Supercharged EM Rails 2', weaponPower:45, ballisticCriticalChance:25, ballisticCriticalDamage:300},

                {id:'pf', name:'Ballistic Recoil Suppressor', weaponPower:20, ballisticDamage:65, ballisticReload:30},

        {id:'pg', name:'Compound Panels E', armourPower:12, ballisticDefence:33, explosiveDefence:33, penetratingDefence:33},

        ];

///////////////
var transformersList = [
        {id:'wa', power: 0, name: ' None'},

        {id:'wb' , name:'A-T Transformer 1', weaponPower:25, bonusDamage:35, ballisticDefence:-10, explosiveDefence:-10, penetratingDefence:-10, radioactiveDefence:-10, armourAbilities:-10},

        {id:'wc', power: 20000, name:'name2', bal: 1000},
        {id:'wd', power: 30000, name:'name3', conc: 2500},
        {id:'we', power: 40000, name:'name4', conc: 5000}
        ];
///////////////

///////////////////////////////////////////////
function Ctrl($scope) {
    $scope.lists = {

    platform:   platformList,
            weapon:     weaponList,
     special:   specialList,
      armour:   armourList,
       trans:   transformersList,
                                    };
////////////////////////////////////////////////
Object.assign($scope, {
       platform: '',
       weapon: '',
       armour1: '',
       armour2: '',
       armour3: '',
       special1: '',
       special2: '',
       special3: '',
       trans1: '',

});
////////////////////////////////////////////////
//var checkURL = $(location).attr("href") //use this line for live site as it will use the URL
//var domain = checkURL.split('&');         //use this line for live site as it will split the URL

var fiddleURL = '   http://www.ahoymearty.co.uk/waynestest/turretbuilder/index.html#&ah&bq&ib&ib&ib&pe&pf&pg&wb' //temp URL for testing - delete this line on live site
var domain = fiddleURL.split('&');      //temp URL split for JSFiddle testing

var platformID = domain[1];
var weaponID = domain[2];
var armour1ID = domain[3];
var armour2ID = domain[4];
var armour3ID = domain[5];
var special1ID = domain[6];
var special2ID = domain[7];
var special3ID = domain[8];
var trans1ID = domain[9];

var platformFromURL = _.max(platformList, function(searchPlatform){ return searchPlatform.id == platformID;});
var weaponFromURL = _.max(weaponList, function(searchWeapon){ return searchWeapon.id == weaponID;});
var armour1FromURL = _.max(armourList, function(searchArmour1){ return searchArmour1.id == armour1ID;});
var armour2FromURL = _.max(armourList, function(searchArmour2){ return searchArmour2.id == armour2ID;});
var armour3FromURL = _.max(armourList, function(searchArmour3){ return searchArmour3.id == armour3ID;});
var special1FromURL = _.max(specialList, function(searchSpecial1){ return searchSpecial1.id == special1ID;});
var special2FromURL = _.max(specialList, function(searchSpecial2){ return searchSpecial2.id == special2ID;});
var special3FromURL = _.max(specialList, function(searchSpecial3){ return searchSpecial3.id == special3ID;});
var trans1FromURL = _.max(transformersList, function(searchTrans1){ return searchTrans1.id == trans1ID;});

$scope.platform = platformFromURL;
$scope.weapon = weaponFromURL;
$scope.armour1 = armour1FromURL;
$scope.armour2 = armour2FromURL;
$scope.armour3 = armour3FromURL;
$scope.special1 = special1FromURL;
$scope.special2 = special2FromURL;
$scope.special3 = special3FromURL;
$scope.trans1 = trans1FromURL;

////////////////////////////////////////////////
$scope.calcTotals = function(codeAddress){
//////////////////////////////////////////////////
//               Base Power Stats               //
//////////////////////////////////////////////////
     $scope.powertotal = Math.round(
     ($scope.weapon.power || 0) +
     ($scope.special1.power || 0) +
     ($scope.special2.power || 0) +
     ($scope.special3.power || 0) +
     ($scope.armour1.power || 0) +
     ($scope.armour2.power || 0) +
     ($scope.armour3.power || 0) +
     ($scope.trans1.power || 0) +
     (($scope.trans1.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.special1.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.special2.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.special3.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.armour1.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.armour2.weaponPower/100) * $scope.weapon.power || 0) +
     (($scope.armour3.weaponPower/100) * $scope.weapon.power || 0)
                                                                );
//////////////////////////////////////////////////
//                 Attack Stats                 //
//////////////////////////////////////////////////
$scope.ballisticDamageTotal = Math.round(
            ($scope.weapon.ballisticDamage || 0) +
        (($scope.special1.ballisticDamage/100) * $scope.weapon.ballisticDamage || 0) +
      (($scope.special2.ballisticDamage/100) * $scope.weapon.ballisticDamage || 0) +
      (($scope.special3.ballisticDamage/100) * $scope.weapon.ballisticDamage || 0)
                                                                        );
////////////////////////////////////
$scope.damageTotal = Math.floor(
                $scope.ballisticDamageTotal +
        (($scope.trans1.bonusDamage/100) * $scope.ballisticDamageTotal || 0)
                                                                );
////////////////////////////////////
$scope.ballisticReloadPercent = Math.floor(
            ($scope.special1.ballisticReload ||0) +
      ($scope.special2.ballisticReload ||0) +
      ($scope.special3.ballisticReload ||0)
                                                                );
////////////////////////////////////
$scope.ballisticDamagePercent = Math.floor(
            ($scope.special1.ballisticDamage ||0) +
      ($scope.special2.ballisticDamage ||0) +
      ($scope.special3.ballisticDamage ||0)
                                                                );
////////////////////////////////////////////////
$scope.explosiveDamagePercent = Math.floor(
            ($scope.special1.explosiveDamage ||0) +
      ($scope.special2.explosiveDamage ||0) +
      ($scope.special3.explosiveDamage ||0)
                                                                );
////////////////////////////////////////////////
$scope.ballisticCriticalChanceTotal = Math.floor(
            ($scope.special1.ballisticCriticalChance ||0) +
      ($scope.special2.ballisticCriticalChance||0)  +
      ($scope.special3.ballisticCriticalChance ||0)
                                                                );
////////////////////////////////////////////////
$scope.ballisticCriticalDamageTotal = Math.floor(
            ($scope.special1.ballisticCriticalDamage ||0) +
      ($scope.special2.ballisticCriticalDamage||0)  +
      ($scope.special3.ballisticCriticalDamage ||0)
                                                                );
////////////////////////////////////////////////

//////////////////////////////////////////////////
//                 Defence Stats                //
//////////////////////////////////////////////////

var balisticDefence1 = ($scope.platform.ballisticDefence) ||0
var balisticDefence2 = (100-(balisticDefence1)) * ($scope.special1.ballisticDefence / 100) ||0
var balisticDefence3 = (100-(balisticDefence1 + balisticDefence2)) * ($scope.special2.ballisticDefence / 100) ||0
var balisticDefence4 = (100-(balisticDefence1 + balisticDefence2 + balisticDefence3)) * ($scope.special3.ballisticDefence / 100) ||0
var balisticDefence5 = (100-(balisticDefence1 + balisticDefence2 + balisticDefence3 + balisticDefence4)) * ($scope.trans1.ballisticDefence / 100) ||0
//////////////////////////////////////////////////
var explosiveDefence1 = ($scope.platform.explosiveDefence) ||0
var explosiveDefence2 = (100-(balisticDefence1)) * ($scope.special1.explosiveDefence / 100) ||0
var explosiveDefence3 = (100-(balisticDefence1 + balisticDefence2)) * ($scope.special2.explosiveDefence / 100) ||0
var explosiveDefence4 = (100-(balisticDefence1 + balisticDefence2 + balisticDefence3)) * ($scope.special3.explosiveDefence / 100) ||0
var explosiveDefence5 = (100-(balisticDefence1 + balisticDefence2 + balisticDefence3 + balisticDefence4)) * ($scope.trans1.explosiveDefence / 100) ||0
//////////////////////////////////////////////////
var penetratingDefence1 = ($scope.platform.penetratingDefence) ||0
var penetratingDefence2 = (100-(penetratingDefence1)) * ($scope.special1.penetratingDefence / 100) ||0
var penetratingDefence3 = (100-(penetratingDefence1 + penetratingDefence2)) * ($scope.special2.explosiveDefence / 100) ||0
var penetratingDefence4 = (100-(penetratingDefence1 + penetratingDefence2 + penetratingDefence3)) * ($scope.special3.penetratingDefence / 100) ||0
var penetratingDefence5 = (100-(penetratingDefence1 + penetratingDefence2 + penetratingDefence3 + penetratingDefence4)) * ($scope.trans1.penetratingDefence / 100) ||0
//////////////////////////////////////////////////
var radioactiveDefence1 = ($scope.platform.radioactiveDefence) ||0
var radioactiveDefence2 = (100-(radioactiveDefence1)) * ($scope.special1.radioactiveDefence / 100) ||0
var radioactiveDefence3 = (100-(radioactiveDefence1 + radioactiveDefence2)) * ($scope.special2.radioactiveDefence / 100) ||0
var radioactiveDefence4 = (100-(radioactiveDefence1 + radioactiveDefence2 + radioactiveDefence3)) * ($scope.special3.radioactiveDefence / 100) ||0
var radioactiveDefence5 = (100-(radioactiveDefence1 + radioactiveDefence2 + radioactiveDefence3 + radioactiveDefence4)) * ($scope.trans1.radioactiveDefence / 100) ||0
//////////////////////////////////////////////////
var corrosiveDefence1 = ($scope.platform.corrosiveDefence) ||0
var corrosiveDefence2 = (100-(corrosiveDefence1)) * ($scope.special1.corrosiveDefence / 100) ||0
var corrosiveDefence3 = (100-(corrosiveDefence1 + corrosiveDefence2)) * ($scope.special2.corrosiveDefence / 100) ||0
var corrosiveDefence4 = (100-(corrosiveDefence1 + corrosiveDefence2 + corrosiveDefence3)) * ($scope.special3.corrosiveDefence / 100) ||0
var corrosiveDefence5 = (100-(corrosiveDefence1 + corrosiveDefence2 + corrosiveDefence3 + corrosiveDefence4)) * ($scope.trans1.corrosiveDefence / 100) ||0
//////////////////////////////////////////////////
var concussiveDefence1 = ($scope.platform.concussiveDefence) ||0
var concussiveDefence2 = (100-(concussiveDefence1)) * ($scope.special1.concussiveDefence / 100) ||0
var concussiveDefence3 = (100-(concussiveDefence1 + concussiveDefence2)) * ($scope.special2.concussiveDefence / 100) ||0
var concussiveDefence4 = (100-(concussiveDefence1 + concussiveDefence2 + concussiveDefence3)) * ($scope.special3.concussiveDefence / 100) ||0
var concussiveDefence5 = (100-(concussiveDefence1 + concussiveDefence2 + concussiveDefence3 + concussiveDefence4)) * ($scope.trans1.concussiveDefence / 100) ||0
//////////////////////////////////////////////////

$scope.ballisticDefenceTotal = Math.round(balisticDefence1 + balisticDefence2 + balisticDefence3  + balisticDefence4 + balisticDefence5)
$scope.explosiveDefenceTotal = Math.round(explosiveDefence1 + explosiveDefence2 + explosiveDefence3  + explosiveDefence4 + explosiveDefence5)
$scope.penetratingDefenceTotal = Math.round(penetratingDefence1 + penetratingDefence2 + penetratingDefence3  + penetratingDefence4 + penetratingDefence5)
$scope.radioactiveDefenceTotal = Math.round(radioactiveDefence1 + radioactiveDefence2 + radioactiveDefence3  + radioactiveDefence4 + radioactiveDefence5)
$scope.corrosiveDefenceTotal = Math.round(corrosiveDefence1 + corrosiveDefence2 + corrosiveDefence3  + corrosiveDefence4 + corrosiveDefence5)
$scope.concussiveDefenceTotal = Math.round(concussiveDefence1 + concussiveDefence2 + concussiveDefence3  + concussiveDefence4 + concussiveDefence5)

//////////////////////////////////////////////////
$scope.armourPointsTotal = $scope.platform.armourPoints +
$scope.armour1.armourPoints  +
$scope.armour2.armourPoints +
$scope.armour3.armourPoints

//////////////////////////////////////////////////
//////////////////////////////////////////////////
var buildPower = $scope.powertotal;
var totalPower = $scope.platform.power + ($scope.armour1.baseMaxPower || 0) + ($scope.armour2.baseMaxPower || 0) + ($scope.armour3.baseMaxPower || 0) ;
var pictureNeeded = $scope.platform.picture;

//change image according to drop menu selection
var imageUrl = "http://ahoymearty.co.uk/turretbuilder/images/turretlvl" + pictureNeeded + ".png"
$('#platformImage').css('background-image', 'url(' + imageUrl + ')');

////////////////////////////////////////////////

} //end of var app

Body:
You can disable select drop down by using ng-disabled.
Check the following code and this revision of your code

<select ng-show="platform.picture > 5" id="loadedspecial3" ng-model='special3' ng-options='value.name for value in lists.special | orderBy: "name"' ng-change='calcTotals()' ng-disabled="special1.name != ' None' || special2.name != ' None'"></select>`