Comparing dates from PocketQuery - velocity

I'm trying to create a simple program that takes a date and marks it as red, green or yellow depending how far from say "today()" it is.
I'm using PocketQuery http://www.scandio.de/en/atlassian-en/plugins/pocketquery
That I use to get a log time from an Oracle database, the query loads fine and I have a nice little $result list.
This date
Below I used the example template I found in the PocketQuery Doc that I use as a first step in getting my script to work. Just to do a simple datetime compare. The variable LOG_TIME is in datetime format.
This script loops through the result and does X for each row.
I've tested the $dateFormatter.getCurrentDateTime() and it outputs the correct time.
So it must be something with the reading of the result I think.
The next step would be to get the compare even more finegrained, say check if the LOG_TIME is say...30 min from a set date and color that yellow but first step would be to get the compare working.
<style>
.high { background: red; }
.low { background: yellow; }
</style>
<table class="pocketquery-table confluenceTable">
<tr>
#foreach ($column in $columns)
<th>$!column</th>
#end
</tr>
#foreach ($row in $result)
<tr class="#if($row.LOG_TIME < $dateFormatter.getCurrentDate())high#{elseif} ($row.LOG_TIME > $dateFormatter.getCurrentDateTime())low#end">
#foreach ($column in $row)
<td>$!column</td>
#end
</tr>
</table>
TLDR:
How do I compare a date I got from pocket query to a date I get from Velocity (dateFormat, date, whatever)?

I would like to update you guys on my progress.
I've got a code working somewhat closely to what I want.
<style>
.high { background: red; font-weight: bold;}
.low { background: greenyellow; font-weight: bold; }
</style>
##create instance of calender
#set($todayAtEight = $calendar.getInstance())
##set time, todo..check if there is a better way of doing this...
$todayAtEight.set(15, 10)
$todayAtEight.set(12, 46)
$todayAtEight.set(13, 5)
$todayAtEight.getTime()
<br/>
<table>
##loop result
#foreach ($row in $result)
##save parameter rowdate
#set($rowDate = $calendar.getInstance())
$rowDate.setTime($row.LOGG_TID)
#if($todayAtEight.before($rowDate))
<tr class="low">
#else
<tr class="high">
#end
<td>
$dateFormatter.formatGivenString("YYYY-MM-dd hh:mm:ss", $row.LOGG_TID)
</td>
<td>
$row.DVH_AREA
</td>
</tr>
#end
</table>

Related

I have words in a cell mixed with word I want to extract. How do I extract the words or delete the words I don't need?

Hello I'm looking for a solution in Pandas or excel. I have a spread sheet with a column that contain words separated by a semicolon
apple - slice123; banana; apple - slice321; orange; citron; apple - slice345;
I want to extract "banana" and "orange" and "citron" into a new column.
I looked for tokenization and pandas extract with word list but I didn't not find a solution.
My original csv contains 1058 rows and the column in question has 1 correct word (orange etc) and 1 error (apple - sliceXYZ) but also 5 correct words and up to 100 errors.
I hope someone has an idea how to solve this.
Edit for clarification.
I have 1027 rows in in the table but only the column with the data of the "fruits" is relevant. I know that I have 27 different fruits somewhere in the columns
Edit: I added a html table for clarification. The word list is used to identify the relevant "fruits" out of the column data and tells me in the results which of the fruits was used in the column data.
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse; padding: 15px;
}
</style>
<table>
<tr>
<td><p><strong>Colunmn 1</strong></p></td>
<td><p><strong>Colunmn 2</strong></p></td>
<td><p><strong>Data</strong></p></td>
<td><p><strong>Result</strong></p></td>
</tr>
<tr>
<td><p>not relevant</p></td>
<td><p>not relevant</p></td>
<td><p>apple - slice123; banana; apple - slice321; orange; citron; apple - slice345</p></td>
<td><p>banana; orange; citron</p></td>
</tr>
<tr>
<td><p>not relevant</p></td>
<td><p>not relevant</p></td>
<td><p>apple - slice435; banana; apple - slice687; orange; citron; apple - slice334; mango; papaya</p></td>
<td><p>banana; orange; citron; mango; papaya</p></td>
</tr>
</table>
<p></p>
<table>
<tr>
<td><p> <strong>word list</strong><p></td>
</tr>
<tr>
<td><p>banana</p></td>
</tr>
<tr>
<td><p>orange<p></td>
</tr>
<tr>
<td><p>citron<p></td>
</tr>
<tr>
<td><p>mango<p></td>
</tr>
<tr>
<td><p>papaya<p></td>
</tr>
</table>
IIUC you can do it like this:
df = pd.DataFrame(
{
"Col2": ["not relevant", "not relevant"],
"Data": [
"apple - slice123; banana; apple - slice321; orange; citron; apple - slice345;",
"apple - slice435; banana; apple - slice687; orange; citron; apple - slice334; mango; papaya",
],
}
)
word_list = ['banana', 'orange', 'citron', 'mango', 'papaya']
two options:
a)
df["Result"] = df["Data"].map(
lambda s: ";".join(
filter(None, [x.strip() for x in s.split(";") if "slice" not in x])
)
)
b)
df["Result"] = df["Data"].map(
lambda s: ";".join(
filter(None, [x.strip() for x in s.split(";") if x.strip() in word_list])
)
)
print(df['Result']
0 banana;orange;citron
1 banana;orange;citron;mango;papaya
Name: Result, dtype: object
If you have Excel 2019 (or greater) and the first cell with data is A1 you could use
=TEXTJOIN("; ",TRUE,(FILTERXML("<c><e>"&SUBSTITUTE(A1,";","</e><e>")&"</e></c>","//e[node() and not(contains(., '-'))]")))
If you have Excel 2013 to 2016 then you could just use the FILTERXML() portion of the above, but it would have to be entered as an array formula, e.g. select cells B1:D1, enter the formula in the formula bar, and press CTRL+Shift+Enter to confirm it
(you're selecting 3 cells because you expect to have 3 results)

How to use variable in the array name

I am building a calendar view of assigned tasks, with an array controlling which tasks should display in each day's cell. I need to reference a varying array key in the v-for loop, but can't find the proper syntax.
My dataset (for tasks on the 5th and 6th of the month) is:
assignments: {
'05':
[
'task one',
'task two'
],
'06':
[
'task three',
'task four'
]
},
This hard-coding to day ['05'] works as I'd like:
<tbody id="calendar-table">
<tr>
<td v-for="(day, index) in calendar.days_array" v-if="index < 7">
<table>
<tr>
{{day}}
</tr>
<tr v-for="task_name in condensedAssignments['05']">
<td>
{{task_name}}
</td>
</tr>
</table>
</td>
</tr>
This gets the attached screenshot:
calendar with tasks within all days
I want to replace the '05' in the second loop with the contents of the variable "day" of the first loop. Variations on v-for="task_name in assignments[{{day}}]" are rejected. I've looked into computed properties or methods, but haven't found a way to pass the current iteration's "day" into them.
How do I get the inner loop to recognize the "day" of the outer loop?
You can use the variable name as index for your condensedAssignments variable, but, I think it can't work because the index is a string and the variable day is a number.
You can do this:
<tr v-for="task_name in condensedAssignments[String(day).padStart(1, '0')]">
<td>{{task_name}}</td>
</tr>
String(day) -> Cast variable to a string
.padStart(2, '0') -> Add one zero at left because your index is '05' then two chars long
Actually, you have several problems here.
First, you should not use v-if and v-for on the same element. If you only want the first n elements, a solution could be to use the slice method : calendar.days_array.slice(0, 7)
The second anomaly is that your assignments variable isn't an Array but an Object. You can search how to iterate through an object or check this Digital Ocean tutorial.
Also, you can call the second v-for statement on your variable instead of harcoding your taskname.
It may looks something like this :
<td v-for="(day, key, i) in calendar.days_array">
<tr>{{ key }}</tr>
<tr v-for="task_name in day">
{{ task_name }}
</tr>
</td>
Thank you to fdisotto for the quick answer. I tried again using a method in the meantime, and was reminded that I have another issue: My "day" field is sometimes null. I was able to get it working, though, with this method:
daysTasks: function(day){
if (!day) {return []};
if (String(day).length < 2) {
day = '0'+day;
}
return this.assignments[day];
},
and this template:
<td v-for="(day, index) in calendar.days_array" :key='day' v-if="index < 7">
<table>
<tr>
{{day}}
</tr>
<tr v-for="task_name in daysTasks(day)" :key='task_name'>
<td>{{task_name}}
</td>
</tr>
Now, only the 5th of the month sees the first two tasks, and the 6th sees the last two.

how to apply filter on JQuery DataTable each columns? [duplicate]

I'm trying to filter table rows in an intelligent way (as opposed to just tons of code that get the job done eventually) but a rather dry of inspiration.
I have 5 columns in my table. At the top of each there is either a dropdown or a textbox with which the user may filter the table data (basically hide the rows that don't apply)
There are plenty of table filtering plugins for jQuery but none that work quite like this, and thats the complicated part :|
Here is a basic filter example http://jsfiddle.net/urf6P/3/
It uses the jquery selector :contains('some text') and :not(:contains('some text')) to decide if each row should be shown or hidden. This might get you going in a direction.
EDITED to include the HTML and javascript from the jsfiddle:
$(function() {
$('#filter1').change(function() {
$("#table td.col1:contains('" + $(this).val() + "')").parent().show();
$("#table td.col1:not(:contains('" + $(this).val() + "'))").parent().hide();
});
});
Slightly enhancing the accepted solution posted by Jeff Treuting, filtering capability can be extended to make it case insensitive. I take no credit for the original solution or even the enhancement. The idea of enhancement was lifted from a solution posted on a different SO post offered by Highway of Life.
Here it goes:
// Define a custom selector icontains instead of overriding the existing expression contains
// A global js asset file will be a good place to put this code
$.expr[':'].icontains = function(a, i, m) {
return $(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
// Now perform the filtering as suggested by #jeff
$(function() {
$('#filter1').on('keyup', function() { // changed 'change' event to 'keyup'. Add a delay if you prefer
$("#table td.col1:icontains('" + $(this).val() + "')").parent().show(); // Use our new selector icontains
$("#table td.col1:not(:icontains('" + $(this).val() + "'))").parent().hide(); // Use our new selector icontains
});
});
This may not be the best way to do it, and I'm not sure about the performance, but an option would be to tag each column (in each row) with an id starting with a column identifier and then a unique number like a record identifier.
For example, if you had a column Produce Name, and the record ID was 763, I would do something like the following:
​​<table id="table1">
<thead>
<tr>
<th>Artist</th>
<th>Album</th>
<th>Genre</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td id="artist-127">Red Hot Chili Peppers</td>
<td id="album-195">Californication</td>
<td id="genre-1">Rock</td>
<td id="price-195">$8.99</td>
</tr>
<tr>
<td id="artist-59">Santana</td>
<td id="album-198">Santana Live</td>
<td id="genre-1">Rock</td>
<td id="price-198">$8.99</td>
</tr>
<tr>
<td id="artist-120">Pink Floyd</td>
<td id="album-183">Dark Side Of The Moon</td>
<td id="genre-1">Rock</td>
<td id="price-183">$8.99</td>
</tr>
</tbody>
</table>
You could then use jQuery to filter based on the start of the id.
For example, if you wanted to filter by the Artist column:
var regex = /Hot/;
$('#table1').find('tbody').find('[id^=artist]').each(function() {
if (!regex.test(this.innerHTML)) {
this.parentNode.style.backgroundColor = '#ff0000';
}
});
You can filter specific column by just adding children[column number] to JQuery filter. Normally, JQuery looks for the keyword from all the columns in every row. If we wanted to filter only ColumnB on below table, we need to add childern[1] to filter as in the script below. IndexOf value -1 means search couldn't match. Anything above -1 will make the whole row visible.
ColumnA | ColumnB | ColumnC
John Doe 1968
Jane Doe 1975
Mike Nike 1990
$("#myInput").on("change", function () {
var value = $(this).val().toLowerCase();
$("#myTable tbody tr").filter(function () {
$(this).toggle($(this.children[1]).text().toLowerCase().indexOf(value) > -1)
});
});
step:1 write the following in .html file
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names..">
<table id="myTable">
<tr class="header">
<th style="width:60%;">Name</th>
<th style="width:40%;">Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbkop</td>
<td>Sweden</td>
</tr>
<tr>
<td>Island Trading</td>
<td>UK</td>
</tr>
<tr>
<td>Koniglich Essen</td>
<td>Germany</td>
</tr>
</table>
step:2 write the following in .js file
function myFunction() {
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}

pdo count not working

I have a page and all the function is working my only problem now is ciunying the record from the databse..
Class.user.php
Public function data($count)
{
$stmt=$this->db->prepare("SELECT COUNT(*) FROM login");
$result=$this->db->prepare($count);
$result->execute();
$number_of_rows=$result->fetchColumn();
}
Index.php
<table>
<thead>
<tr>
<th>2014</th>
</tr>
</thead>
<tbody>
<?php
$count="SELECT COUNT(*) FROM login";
$crud->data($count);
?>
The problem is that its not showing the count..
You're writing the same query as function argument, but also inside the function itself. And you're only really using one. This is nonsense. Dedicate your method to return the count, don't make the query a parameter.
prepareing the statement is pointless in this case, since you're neither reusing it nor are you binding any values. You can simply query() it directly.
The clincher: you're neither outputting nor returning the count, so it's very very expected that it doesn't show up anywhere.
Here's a sane version:
public function getCount() {
$result = $this->db->query('SELECT COUNT(*) FROM login');
return $result->fetchColumn();
}
<tbody>
<tr>
<td>
<?php echo $crud->getCount(); ?>
I think I usually do it like this link
$sql= "SELECT COUNT(*) FROM login";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$row =$stmt->fetchObject();
then to output it you would have to ECHO
<table>
<tbody>
<tr>
<td>
<?php echo $row['count'];?>
</td>
</tr>
</tbody>
</table>

Auto navigate (scroll) to certain table row

I have a table with few thousand records on few pages in a simple html table.. I made a search function that works fine apart from one thing... It displays only one result in a table (which is great cause it means it works!).But... I was wondering is there a way to display back the table with all records, with the one that i was searching for in the middle and highlighted? Here's a simplified table that I have :
<table class="nogap" cellpadding="1" bgcolor="#00000" cellspacing="1" style="margin:110px 0 0 5px; width:100%; border-color:#B6D6F6;" >
<tbody>
<?php include 'dbconn.php';?>
$con = mysqli_connect($host,$user,$pass,$db) or (header( 'Location: errorpage.php' ));
if (mysqli_connect_errno($con)) { header( 'Location: errorpage.php' ); }
$sql = "SELECT * FROM $tb1 ORDER BY (Serial_num +1) LIMIT $offset, $rowsperpage";
$result = mysqli_query($con, $sql) or (header( 'Location: errorpage.php' ));
$row = mysqli_num_rows($result);
while ($row = $result->fetch_assoc())
{
$product = $row['Prod_type'].$row['Serial_num'];
<tr id="mstrTable" class="lovelyrow">
<td width="5%"><?php echo $product;?></td>
<td width="5%"><?php echo $row['Customer'];?></td>
<td width="7%">
<a href="#"
onmouseover="ajax_showTooltip(window.event,'getptn.php?prd=<?php echo $p;?>',this);return false"
onmouseout="ajax_hideTooltip()">
<?php echo$row['Prod_info'];?>
</a>
</td>
</tr>
}
</table>
Thanks!
First of all don't give the same html id attribute to each row (mstrTable). Html Ids should be unique per page.
Instead mark table rows with unique ids, eg:
$html .= "<td id='row_".$row['id']."'>"
Then do a search query first, remember item id, figure out what page should be queried, query the whole page, attach classess 'greyedout' and 'highlighted' to rows accordingly and then you might try this javascript function to scroll down to the item:
https://developer.mozilla.org/en-US/docs/Web/API/element.scrollIntoView