Is there a solution to this formula stopping an AutoSort script - sorting

I am attempting to learn to script as I develop a project so please forgive me if I ask this question incorrectly.
I have created an AutoSort script for a google sheets document to sort a list of players by "Weight". It works fine until I add the following formula. Once I add this formula, my data is to be sorted by Column 7, largest to smallest and doesn't completely. The odd part of this is that the players that are out of order are listed as Substitutes.
The way this sheet works.
The Match Tool tab is where players are selected from Data Validation cells.
The Data Validation list comes from the MR1 Tab.
The MR1 tab gets it list based on an importrange defined in the MRTool.
This comes from a larger document and I've extracted the vital parts to make the error happen. I've tried to run a bare-bones version with only text and the AutoSort script and it sorts correctly. I have also tried changing which column the AutoSort looks in and it works correctly.
The formula that stops the script from working:
=if(or(C10="",C10=". Blank"),"",iferror(index('MR1'!$B$8:$H$87,(match(C10,'MR1'!$N$8:$N$87,0))),"Player Not Found"))
The Script for the AutoSort:
var roster = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Match Tool");
var range1 = roster.getRange("B10:K59");
var range2 = roster.getRange("N10:W59");
range1.sort( [{ column : 7, ascending: false}, { column : 11, ascending: false}] );
range2.sort( [{ column : 19, ascending: false}, { column : 23, ascending: false}] );
}
function SortLeft() {
var roster = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Match Tool");
var range1 = roster.getRange("B10:K59");
range1.sort( [{ column : 7, ascending: false}, { column : 11, ascending: false}] );
}
function SortRight() {
var roster = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Match Tool");
var range2 = roster.getRange("N10:W59");
// It seems that column numbers are always sequential from the first one, even if you are addressing a range. Hence using 14/18 here instead of 4/8
range2.sort( [{ column : 19, ascending: false}, { column : 23, ascending: false}] );
}
function SortSelection() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getActiveRange();
var firstcol = range.getColumn();
var lastcol = range.getLastColumn();
//Before sorting, this code checks to make sure that Clan through Combined heroes is selected on one side or the other. If not, an error appears.
if (firstcol == 2 && lastcol == 11 ) { range.sort( [{ column : 7, ascending: false}, { column : 11, ascending: false}] )} //&& lastcol == 11
else if ( firstcol == 14 && lastcol == 23 ) { range.sort( [{ column : 19, ascending: false}, { column : 23, ascending: false}] )} //&& lastcol == 23
else { SpreadsheetApp.getUi().alert('You can only sort selections that include all 8 data columns, from Clan to Notes.');}
}
function onEdit(e){
var roster = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Match Tool");
var autosort = roster.getRange(6, 13).getValue();
var range1 = roster.getRange("B10:K59");
var range2 = roster.getRange("N10:W59");
// if('B3' === GWL) {
// SpreadsheetApp.getActiveSheet().getRange('K2').setValue('40');
// }
// test if K2 (war size) was modified
if (e.source.getActiveSheet().getName() == "Match Tool" && e.range.rowStart === 6 && e.range.columnStart === 13) {
moveToSub();
}
//preform autosort if on
if ( autosort == "On" ){
range1.sort( [{ column : 7, ascending: false}, { column : 11, ascending: false}] );
range2.sort( [{ column : 19, ascending: false}, { column : 23, ascending: false}] );
}
}
I expect players to be sorted by column 7 (column G) descending and then column 11 (Column K) descending. What I'm getting is certain players not sorted correctly.
I am getting - 132, 131, 131, 113, 111, 132, 113, 90, 88, 87, 86.
I should see - 132, 132, 131, 131, 113, 113, 111, 90, 88, 87, 86.
Thank you for taking the time to help me.

After some help from a friend, we realized the problem wasn't anything to do with the script on this page, it was how the data was entered on the sheet the data was imported in from. Some numbers were entered as numerals while others were entered in as text. By changing the text to numerals, the script performed as expected.
So the moral of the story is, check to make sure the data being sort is of the same type.

Related

Problem with combobox, it didn't load de options (pyqt5)

I have a program that when I press a pushbutton it loads the options of my combombox, I have three, but for a unknown reason only two works. This function read a .txt file, and then put the strings in the combobox. I tried with addItem() and addItems(), made function again and it didn't work. The function read another two combobox and then loads the options.This is the function:
def cargar_combobox_flujos2(self,event):
anho = int(self.ui.combobox_anho.itemText(self.ui.combobox_anho.currentIndex()))
mes_input = self.ui.combobox_mes.itemText(self.ui.combobox_mes.currentIndex())
dic = {'Enero': 1, 'Febrero': 2, 'Marzo': 3, 'Abril': 4, 'Junio': 5, 'Julio': 7, 'Agosto': 8, 'Septiembre': 9,
'Octubre': 10, 'Noviembre': 11, 'Diciembre': 12}
mes = int(dic.get(mes_input))
lista_ssee=[]
nombre_txt='Graficos Flujos/lista_cbbx_'+str(anho)+'_'+str(mes)+'.txt'
if os.path.isfile(nombre_txt)==True:
archivo = open(nombre_txt, 'r')
c=archivo.read()
lista=c.split(',')
for i in lista:
lista_ssee.append(i)
archivo.close()
option_barras= self.ui.comboBox_barras_CMg2.count()
if option_barras > 1:
self.ui.comboBox_barras_CMg2.clear()
for barra in lista_ssee:
self.ui.comboBox_barras_CMg2.addItems(barra)

Getting max and min from two different sets in json

I haven't found a solution with data set up quite like mine...
var marketshare = [
{"store": "store1", "share": "5.3%", "q1count": 2, "q2count": 4, "q3count": 0},
{"store": "store2","share": "1.9%", "q1count": 5, "q2count": 10, "q3count": 0},
{"store": "store3", "share": "2.5%", "q1count": 3, "q2count": 6, "q3count": 0}
];
Code so far, returning undefined...
var minDataPoint = d3.min( d3.values(marketshare.q1count) ); //Expecting 2 from store 1
var maxDataPoint = d3.max( d3.values(marketshare.q2count) ); //Expecting 10 from store 2
I'm a little overwhelmed by d3.keys, d3.values, d3.maps, converting to array, etc. Any explanations or nudges would be appreciated.
I think you're looking for something like this instead:
d3.min(marketshare, function(d){ return d.q1count; }) // => 2.
You can pass an accessor function as the second argument to d3.min/d3.max.

Creating a new column in JMP using an if condition from another column

I am very new in JMP so I am still feeling around.
I want to create a new column called "Status" in JMP. This status is character and depends on the value of the column "Grade". If the value of the entry in column "Grade" is zero, the value of the entry in column "Status" should be "fail". If the "Grade" value is greater than 100, the entry in column "Status" should be "invalid". If the :Grade" value is less than 0, the "Status" value should be "invalid". This should be simple. But somehow, my script won't work:
dt = Current Data Table();
dt << New Column("Status", Character, Formula(
If(:Name( "Grade" )==0, "fail",
:Name( "Grade" )>100, "invalid",
:Name( "Grade" )<0, "invalid")
));
Can you help me debug this script?
I just tried the script and the formula is working for me.
Here is some JSL which is a bit more complete which also adds the "Grade" column upon which "Status" depends.
dt = Current Data Table();
dt << New Column( "Grade",
Numeric,
"Continuous",
Format( "Best", 12 ),
);
dt << New Column( "Status",
Character,
"Nominal",
Formula(
If(
:Grade == 0, "fail",
:Grade > 100, "invalid",
:Grade < 0, "invalid"
)
)
);
Perhaps the issue is that you don't already have a data table opened with a Grade column? Here's a script to create a brand new table with the formula and some values.
New Table( "Grading Test",
Add Rows( 7 ),
New Column( "Grade",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [45, 20, 100, 101, -4, 0, 120] )
),
New Column( "Status",
Character,
"Nominal",
Formula(
If(
:Grade == 0, "fail",
:Grade > 100, "invalid",
:Grade < 0, "invalid"
)
)
)
);
I created that by interactively creating the table and using the red-triangle menu and selected "Copy Table Script".
I tried JMP 12.0, which version are you using?

Realm Cocoa: skipped item when iterating through RLMArray

I have a very strange issue when iterating through RLMArray. I do something like this:
let tickets = Ticket.objectsWhere("pendingSync = true")
for ticket in tickets {
print("1. " + ticket.id + ",")
}
realm.beginWriteTransaction()
for ticket in tickets {
let ticket = ticket as Ticket
ticket.pendingSync = false
print("2. " + ticket.id + ",")
}
realm.commitWriteTransaction()
Strangely enough, the output is
1. 125, 1. 127, 1. 123,
2. 125, 2. 123
and NOT
1. 125, 1. 127, 1. 123,
2. 125, 2. 127, 2. 123
Shortly, the second iteration skips one item. How is this possible? Any ideas?
Thanks!
Mutating items during enumeration is not currently supported in Realm, but will be supported in the upcoming 0.95 release.

how to send array of values to a query dynamically in codeigniter

The code in model is
public function get_report6_8($type, $filter_id=NULL) {
$values = array($filter_id);
$select = '';
if ($filter_id && $type == 'jh') {
$select = 'and natbuild_rep.jh_rep_id = ?';
}
else if ($filter_id && $type == 'natbuild') {
$select = 'and natbuild_principal.id = ?';
}
$sql = "select sum(total) total
from (
select value_of_sale total
from lead
left join natbuild_rep
on natbuild_rep.mobile = lead.mobile
left join natbuild_store
on natbuild_store.id = natbuild_rep.store_id
left join natbuild_principal
on natbuild_principal.store_group = ifnull(natbuild_store.store_group2, natbuild_store.store_group)
where (status = 1 OR status = 2)
and value_of_sale is not null
{$select}
group by lead.id
) temp";
return $this->db->query($sql, $values)->row();
}
The code in controller is
$data['report8'] = $this->lead_report_model->get_report6_8($type, $this->input->post('filter'));
code in view is
Grand Total: $total)) ? $report8->total: 0;?>
if I run query like
select sum(total) total
from (
select value_of_sale total
from lead
left join natbuild_rep
on natbuild_rep.mobile = lead.mobile
left join natbuild_store
on natbuild_store.id = natbuild_rep.store_id
left join natbuild_principal
on natbuild_principal.store_group = ifnull(natbuild_store.store_group2, natbuild_store.store_group)
where (status = 1 OR status = 2)
and value_of_sale is not null
and natbuild_principal.id in (18, 30, 31, 35, 33, 25, 23, 15, 8, 6, 5, 29, 7, 3, 2, 1, 24, 27, 22, 21, 20, 26, 36)
group by lead.id ) temp
the result is right. please help how can I send array of values to the $select. This happens when I select grand total from a dropdown which contains all other values up there.
your dropdown is multiselect so it will pass an array with the values.
use
implode(",", $dropdownSelections);
$select = 'and natbuild_principal.id in ('.implode(",", $dropdownSelections).')';

Resources