Array & slideshow - slideshow

I'm using the below code in order to display a photo in slide show, i need to display: name,job and quote for each person, but actually only photos change on time interval specified ...can anyone help?
var img1 = document.getElementById("img1");
var testname = document.getElementById("testname");
var testjob = document.getElementById("testjob");
var testpa = document.getElementById("testpa");
var currentPos = 0;
var images = ["ch1.jpg", "ch2.jpg", "ch3.jpg"]
var testname = [“John Smith” ,”Jan Rosso”,”Raphael Matthew”]
var testjob = [“Manager” ,”Director”,”Supervisor”]
var testpa = [“I like this company”,”It’s amazing”,”Wondeful atmospher”]
function volgendefoto() {
if (++currentPos >= images.length)
currentPos = 0;
img1.src = images[currentPos];
testname.value = testname[currentPos];
testjob.value = testjob[currentPos];
testpa.value = testpa[currentPos];
}
setInterval(volgendefoto, 3000);
function test(){
document.getElementById('text').value=document.getElementById('testname').value
}

testName and the others may need to be updated via innerHTML
function volgendefoto() {
if (++currentPos >= images.length)
currentPos = 0;
img1.src = images[currentPos];
testname.innerHtml = testname[currentPos];
testjob.innerHtml = testjob[currentPos];
testpa.innerHtml = testpa[currentPos];
}

Related

Disabling stacking candles on AmCharts v4 Candlestick chart

I am building a simple candlestick chart in a hourly timeframe. I figured out out to avoid candles to being grouped within the same day using both "dateFormat" and "inputDateFormat" parameters. For some reason, depending on the dataset, it doesn't always work.
Below two examples that differ only for the dataset (chart.data).
Any idea about what is wrong?
Thanks
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>
<!-- Chart code -->
<script>
am4core.ready(function() {
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
// Create chart
var chart = am4core.create("chartdiv_stock", am4charts.XYChart);
// Load data
chart.data=[{"Date":"2020-10-29 12:00:00","Open":"329.21","High":"329.87","Low":"327.82","Close":"328.43","Volume":"9903193"},{"Date":"2020-10-29 11:00:00","Open":"327.87","High":"329.82","Low":"327.11","Close":"329.22","Volume":"14505192"},{"Date":"2020-10-29 10:00:00","Open":"327.08","High":"329.485","Low":"325.09","Close":"327.83","Volume":"11636626"}];
chart.leftAxesContainer.layout = "vertical";
chart.dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss";
chart.dateFormatter.inputDateFormat = "yyyy-MM-dd HH:mm:ss";
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
dateAxis.renderer.grid.template.location = 0;
dateAxis.renderer.minGridDistance = 60;
dateAxis.skipEmptyPeriods=true;
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.tooltip.disabled = false;
valueAxis.renderer.grid.template.strokeOpacity = 0;
dateAxis.renderer.grid.template.strokeOpacity = 0;
var series = chart.series.push(new am4charts.CandlestickSeries());
series.dataFields.dateX = "Date";
series.dataFields.openValueY = "Open";
series.dataFields.valueY = "Close";
series.dataFields.lowValueY = "Low";
series.dataFields.highValueY = "High";
//series.tooltipText = "Open: [bold]${openValueY.value}[/]\nLow: [bold]${lowValueY.value}[/]\nHigh: [bold]${highValueY.value}[/]\nClose: [bold]${valueY.value}[/]";
series.connect = true;
series.dropFromOpenState.properties.fill = am4core.color("black");
series.dropFromOpenState.properties.stroke = am4core.color("black");
series.riseFromOpenState.properties.fill = am4core.color("white");
series.riseFromOpenState.properties.stroke = am4core.color("black");
series.riseFromPreviousState.properties.fillOpacity = 0;
series.dropFromPreviousState.properties.fillOpacity = 1;
chart.cursor = new am4charts.XYCursor();
chart.scrollbarX = new am4core.Scrollbar();
}); // end am4core.ready()
</script>
<div id="chartdiv_stock" style="width:100%;height:500px;float:left;" ></div>
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>
<!-- Chart code -->
<script>
am4core.ready(function() {
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
// Create chart
var chart = am4core.create("chartdiv_stock", am4charts.XYChart);
// Load data
chart.data=[{"Date":"2020-12-04 15:00:00","Open":"368.74","High":"369.28","Low":"368.55","Close":"369.2","Volume":"4558835"},{"Date":"2020-12-04 16:00:00","Open":"369.2","High":"369.85","Low":"368.67","Close":"369.83","Volume":"13766958"},{"Date":"2020-12-04 17:00:00","Open":"369.82","High":"369.94","Low":"368.94","Close":"369.01","Volume":"7618573"},{"Date":"2020-12-04 18:00:00","Open":"369","High":"369.85","Low":"369","Close":"369.15","Volume":"413998"},{"Date":"2020-12-04 19:00:00","Open":"369.15","High":"369.34","Low":"369.11","Close":"369.19","Volume":"38254"},{"Date":"2020-12-04 20:00:00","Open":"369.21","High":"369.25","Low":"369.14","Close":"369.22","Volume":"22622"}];
chart.leftAxesContainer.layout = "vertical";
chart.dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss";
chart.dateFormatter.inputDateFormat = "yyyy-MM-dd HH:mm:ss";
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
dateAxis.renderer.grid.template.location = 0;
dateAxis.renderer.minGridDistance = 60;
dateAxis.skipEmptyPeriods=true;
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.tooltip.disabled = false;
valueAxis.renderer.grid.template.strokeOpacity = 0;
dateAxis.renderer.grid.template.strokeOpacity = 0;
var series = chart.series.push(new am4charts.CandlestickSeries());
series.dataFields.dateX = "Date";
series.dataFields.openValueY = "Open";
series.dataFields.valueY = "Close";
series.dataFields.lowValueY = "Low";
series.dataFields.highValueY = "High";
//series.tooltipText = "Open: [bold]${openValueY.value}[/]\nLow: [bold]${lowValueY.value}[/]\nHigh: [bold]${highValueY.value}[/]\nClose: [bold]${valueY.value}[/]";
series.connect = true;
series.dropFromOpenState.properties.fill = am4core.color("black");
series.dropFromOpenState.properties.stroke = am4core.color("black");
series.riseFromOpenState.properties.fill = am4core.color("white");
series.riseFromOpenState.properties.stroke = am4core.color("black");
series.riseFromPreviousState.properties.fillOpacity = 0;
series.dropFromPreviousState.properties.fillOpacity = 1;
chart.cursor = new am4charts.XYCursor();
chart.scrollbarX = new am4core.Scrollbar();
}); // end am4core.ready()
</script>
<div id="chartdiv_stock" style="width:100%;height:500px;float:left;" ></div>
It's seems it was due to the ordering, the "not working" case had Data descending. Changing to ascending solved the issue.

Regex in textreplace google app script is not working

Trying to replace text + date just by date using regex, but it not works:
function myfunction() {
var SourceFolder = DriveApp.getFolderById("");
var Files = SourceFolder.getFiles()
var body = DocumentApp.getActiveDocument().getBody();
while(Files.hasNext()) {
var file = Files.next();
body.replaceText("Date: \d{2}.\d{2}.\d{4}", "31.10.2020")
}
}
Thanks
In your code, var body = DocumentApp.getActiveDocument().getBody(); is declared outside of the loop, so you always refer to the active document body in your while loop.
You may use
while(Files.hasNext()) {
var file = Files.next();
var doc = DocumentApp.openById(file.getId());
var body = doc.getBody();
body.replaceText("Date: \\d{2}\\.\\d{2}\\.\\d{4}", "31.10.2020")
}
The point here is to use double backslashes in the pattern, and escape the dot chars since otherwise a . matches any char but a line break char.
function replace_text() {
// Get speadshhet with ID
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Returns cell with ID (User will insert his or her folder ID in cell B3)
var range = sheet.getRange(3, 2);
var values = range.getDisplayValue();
// Get folder by ID - insert your folder ID
var SourceFolder = DriveApp.getFolderById(values);
// Iterate throw all files in folder
var Files = SourceFolder.getFiles();
while(Files.hasNext()) {
var file = Files.next();
// Get all documents ID
var doc = DocumentApp.openById(file.getId());
// Get text body to replace
var body = doc.getBody();
// Insert header in document + alignment
var header = body.insertParagraph(0, 'TEXT');
header.setAlignment(DocumentApp.HorizontalAlignment.RIGHT)
// Text style
var style = {};
//style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Arial';
style[DocumentApp.Attribute.FONT_SIZE] = 9;
style[DocumentApp.Attribute.FOREGROUND_COLOR] = '#000000';
body.setAttributes(style)
Logger.log(body)
// Replacing text
body.replaceText("Text", " ");
body.replaceText("Date:\\s*\\d{2}\\.\\d{2}\\.\\d{4}", "31.10.2020")
var paragraphs = body.getParagraphs();
for (var i = 7; i < paragraphs.length; i++) {
var paragraph = paragraphs[i];
paragraph.setAlignment(DocumentApp.Horizontal`enter code here`Alignment.LEFT)
}
}
}

Problem with If/Then code with Google Sheet Script

Someone please help.
I am trying to create a simple script which records button presses in order.
I have:
function P1Buzzer() {
var sheet = SpreadsheetApp.getActiveSheet();
var row = 6;
var col = 1;
var Name = sheet.getRange(row, col).getValue();
var sheet = SpreadsheetApp.getActiveSheet();
var row = 192;
var col = 1;
var AnswerPosition = sheet.getRange(row, col).getValue();
if (AnswerPosition = 1) {
sheet.getRange(199, 1).setValue(Name);
var AnswerPosition = AnswerPosition + 1
sheet.getRange(192, 1).setValue(AnswerPosition);
}
if (AnswerPosition = 2) {
sheet.getRange(200, 1).setValue(Name);
var AnswerPosition = AnswerPosition + 1
sheet.getRange(192, 1).setValue(AnswerPosition);
}
}
The problem I have is that when I run the script it does both the commands, ignoring the if command.
Any ideas?
First, you are setting the value to 1 by using = instead of ==. Second, if it was 1, you add one to it and then check to see if it is 2. I'll bet it is!
if (AnswerPosition == 1) {
sheet.getRange(199, 1).setValue(Name);
var AnswerPosition = AnswerPosition + 1
sheet.getRange(192, 1).setValue(AnswerPosition);
} else if (AnswerPosition == 2) {
...

Google Apps Scripts If function not skipping rows with null value

I am writing a function that will search a spreadsheet for days an employee has worked hours, create an array with the values for job number, job name, employee name, hours, and date, and then put them onto another spreadsheet. It also only shows hours that were within the past 8 days so that time can be worked out for the week when we have to report hours (I'm scheduling it to run the day time is due). I also have been filtering out days with blank hours, which limits the amount of data that gets copied over.
I am encountering an issue where on one employee the function to skip the blank hours does not work. For other employees I have been able to use "" to indicate an empty cell. I have also tried to use (null) as a value, but that only ignores 6 of 7 days (It still logs days with no hours that are adjacent to cells that calculate hours in the week).
What I can't figure out is why this doesn't work on just one sheet out of the whole Google Sheets document. I have simplified my spreadsheet to reduce personal information, and to make it easier to parse the script, but in my original document I track 6 employees with similar code, and only one is showing this issue.
https://docs.google.com/spreadsheets/d/1ve0EPVQJ2vmWG1NYHMncw1ZljP3yXd28dMeNC38Jiy4/edit?usp=sharing
Is a link to the spreadsheet. Code is below.
function shoptime(){
var ss = SpreadsheetApp.getActive().getId();
var stephensheet = Sheets.Spreadsheets.Values.get(ss, 'Stephen!A2:G');
var tiffanysheet = Sheets.Spreadsheets.Values.get(ss, 'Tiffany!A2:G');
var scripts = SpreadsheetApp.getActive().getSheetByName("Scripts");
var currentDate = new Date();
var pastweek = new Date();
pastweek.setDate(currentDate.getDate() -8);
var array=[];
for (var a = 0; a < stephensheet.values.length; a++){
var jobdate = stephensheet.values[a][1];
var intime = stephensheet.values[a][2];
var outtime = stephensheet.values[a][3];
var dailyhours = stephensheet.values[a][4];
if (new Date(jobdate) > pastweek){
if (dailyhours != (null)){
array.push(["NA","Office","Stephen",dailyhours,jobdate]);
}
}
}
for (var a = 0; a < tiffanysheet.values.length; a++){
var jobdate = tiffanysheet.values[a][1];
var intime = tiffanysheet.values[a][2];
var outtime = tiffanysheet.values[a][3];
var dailyhours = tiffanysheet.values[a][4];
if (new Date(jobdate) > pastweek){
if (dailyhours != ("")){
array.push(["NA","Office","Tiffany",dailyhours,jobdate]);
}
}
}
if(array[0]){
scripts.getRange(scripts.getLastRow()+1,1,array.length,5).setValues(array);
}
SpreadsheetApp.flush();
}
I'm not sure of the exact issue but checking for cells that have a value rather than cells that are not null should work for you.
function shoptime(){
var ss = SpreadsheetApp.getActive().getId();
var stephensheet = Sheets.Spreadsheets.Values.get(ss, 'Stephen!A2:G');
var tiffanysheet = Sheets.Spreadsheets.Values.get(ss, 'Tiffany!A2:G');
var scripts = SpreadsheetApp.getActive().getSheetByName("Scripts");
var currentDate = new Date();
var pastweek = new Date();
pastweek.setDate(currentDate.getDate() -8);
var array=[];
for (var a = 0; a < stephensheet.values.length; a++){
var jobdate = stephensheet.values[a][1];
var intime = stephensheet.values[a][2];
var outtime = stephensheet.values[a][3];
var dailyhours = stephensheet.values[a][4];
if (new Date(jobdate) > pastweek){
if (dailyhours){
array.push(["NA","Office","Stephen",dailyhours,jobdate]);
}
}
}
for (var a = 0; a < tiffanysheet.values.length; a++){
var jobdate = tiffanysheet.values[a][1];
var intime = tiffanysheet.values[a][2];
var outtime = tiffanysheet.values[a][3];
var dailyhours = tiffanysheet.values[a][4];
if (new Date(jobdate) > pastweek){
if (dailyhours){
array.push(["NA","Office","Tiffany",dailyhours,jobdate]);
}
}
}
if(array[0]){
scripts.getRange(scripts.getLastRow()+1,1,array.length,5).setValues(array);
}
SpreadsheetApp.flush();
}
And to modify the code to use the built-in service with is much more straight forward in this case;
function shoptime(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var stephensheet = ss.getSheetByName('Stephen').getDataRange().getValues();
var tiffanysheet = ss.getSheetByName('Tiffany').getDataRange().getValues();
var scripts = ss.getSheetByName("Scripts");
var currentDate = new Date();
var pastweek = new Date();
pastweek.setDate(currentDate.getDate() -8);
var array=[];
for (var a = 0; a < stephensheet.length; a++){
var jobdate = stephensheet[a][1];
var intime = stephensheet[a][2];
var outtime = stephensheet[a][3];
var dailyhours = stephensheet[a][4];
if (new Date(jobdate) > pastweek){
if (dailyhours != ""){
array.push(["NA","Office","Stephen",dailyhours,jobdate]);
}
}
}
for (var a = 0; a < tiffanysheet.length; a++){
var jobdate = tiffanysheet[a][1];
var intime = tiffanysheet[a][2];
var outtime = tiffanysheet[a][3];
var dailyhours = tiffanysheet[a][4];
if (new Date(jobdate) > pastweek){
if (dailyhours != ""){
array.push(["NA","Office","Tiffany",dailyhours,jobdate]);
}
}
}
if(array[0]){
scripts.getRange(scripts.getLastRow()+1,1,array.length,5).setValues(array);
}
SpreadsheetApp.flush();
}
Finally, if you are scraping data from 6 sheets in the exact same format then a another loop and an array of the sheet names will save on repetition of code
function shoptime() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ['Stephen', 'Tiffany'] // add the aditional sheet names here
var scripts = SpreadsheetApp.getActive().getSheetByName("Scripts");
var currentDate = new Date();
var pastweek = new Date();
pastweek.setDate(currentDate.getDate() - 8);
var array = [];
for (var i = 0; i < sheets.length; i++) {
var sheet = ss.getSheetByName(sheets[i]);
var data = sheet.getDataRange().getValues();
for (var a = 0; a < data.length; a++) {
var jobdate = data[a][1];
var intime = data[a][2];
var outtime = data[a][3];
var dailyhours = data[a][4];
if (new Date(jobdate) > pastweek) {
if (dailyhours) {
array.push(["NA", "Office", sheets[i], dailyhours, jobdate]);
}
}
}
}
if (array[0]) {
scripts.getRange(scripts.getLastRow() + 1, 1, array.length, 5).setValues(array);
}
SpreadsheetApp.flush();
}

How to Load movie clip with a conditional dynamic text. IF...else

I have two dynamic texts, both of them are going to generate numbers. If one has a greater value then the other one, a movie clip must be loaded, else, another movie clip must be loaded.
It's also important to note that I need to choose exactly the place that this movie clip will be load.
I create this code, but it's not working.
btn01.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_27);
function fl_ClickToGoToAndStopAtFrame_27(event:MouseEvent):void
{
var texto.text;
function testGuess():void{
if (parseInt(texto.text) == 8)
var fl_MyInstance_3:greenlight = new greenlight();
addChild(fl_MyInstance_3);
}}}
stop();
// timer loading
var timer:Timer = new Timer(2500);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
function onTimer(evt:TimerEvent):void {
//primeiro indicador parte
var loader:URLLoader = new URLLoader(new URLRequest("bdaily.txt"));
loader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void {
var loadedText:URLLoader = URLLoader(event.target);
bdaily.text = loadedText.data;
}
// segundo indicador.
var loader1:URLLoader = new URLLoader(new URLRequest("bmtd.txt"));
loader1.addEventListener(Event.COMPLETE, completeHandler1);
function completeHandler1(event:Event):void {
var loadedText1:URLLoader = URLLoader(event.target);
bmtd.text = loadedText1.data;
}
//terceiro indicador
var loader2:URLLoader = new URLLoader(new URLRequest("bwtd.txt"));
loader2.addEventListener(Event.COMPLETE, completeHandler2);
function completeHandler2(event:Event):void {
var loadedText2:URLLoader = URLLoader(event.target);
bwtd.text = loadedText2.data;
}
//terceiro indicador
var loader3:URLLoader = new URLLoader(new URLRequest("basketdtarget.txt"));
loader3.addEventListener(Event.COMPLETE, completeHandler3);
function completeHandler3(event:Event):void {
var loadedText3:URLLoader = URLLoader(event.target);
basketdtarget.text = loadedText3.data;
}
var loader4:URLLoader = new URLLoader(new URLRequest("basketwtdtarget.txt"));
loader4.addEventListener(Event.COMPLETE, completeHandler4);
function completeHandler4(event:Event):void {
var loadedText4:URLLoader = URLLoader(event.target);
basketwtdtarget.text = loadedText4.data;
}
var loader5:URLLoader = new URLLoader(new URLRequest("basketmtdtarget.txt"));
loader5.addEventListener(Event.COMPLETE, completeHandler5);
function completeHandler5(event:Event):void {
var loadedText5:URLLoader = URLLoader(event.target);
basketmtdtarget.text = loadedText5.data;
}
//condicionais para gerar movieclip condicional
var clp_index = parseInt(bdaily.text) >= parseInt(basketdtarget.text) ? 1 : 2
var new_clp = clp_index == 1 ? new clp_01() : new clp_02()
addChild(new_clp)
var clp_index2 = parseInt(bwtd.text) >= parseInt(basketwtdtarget.text) ? 1 : 2
var new_clp2 = clp_index2 == 1 ? new clp_03() : new clp_04()
addChild(new_clp2)
var clp_index3 = parseInt(bmtd.text) >= parseInt(basketmtdtarget.text) ? 1 : 2
var new_clp3 = clp_index3 == 1 ? new clp_05() : new clp_06()
addChild(new_clp3)
}
try this :
btn.addEventListener(MouseEvent.CLICK, btn_on_Press);
function btn_on_Press(e:MouseEvent):void {
var clp_index = parseInt(txt_01.text) > parseInt(txt_02.text) ? 1 : 2
var new_clp = clp_index == 1 ? new clp_01() : new clp_02()
// to set the new_clp position
new_clp.x = 250 // left position
new_clp.y = 50 // top position
addChild(new_clp)
}
Last Edit :
stop()
var new_clp, new_clp2, new_clp3
var timer:Timer = new Timer(3000)
timer.addEventListener(TimerEvent.TIMER, onTimer)
timer.start()
function onTimer(evt:TimerEvent):void {
var loader:URLLoader = new URLLoader(new URLRequest('bdaily.txt'))
loader.addEventListener(Event.COMPLETE, function(e:Event){
bdaily.text = loader.data
})
var loader1:URLLoader = new URLLoader(new URLRequest('bmtd.txt'))
loader1.addEventListener(Event.COMPLETE, function(e:Event){
bmtd.text = loader1.data
})
var loader2:URLLoader = new URLLoader(new URLRequest('bwtd.txt'))
loader2.addEventListener(Event.COMPLETE, function(e:Event){
bwtd.text = loader2.data
})
var loader3:URLLoader = new URLLoader(new URLRequest('basketdtarget.txt'))
loader3.addEventListener(Event.COMPLETE, function(e:Event){
basketdtarget.text = loader3.data
})
var loader4:URLLoader = new URLLoader(new URLRequest('basketwtdtarget.txt'))
loader4.addEventListener(Event.COMPLETE, function(e:Event){
basketwtdtarget.text = loader4.data
})
var loader5:URLLoader = new URLLoader(new URLRequest('basketmtdtarget.txt'))
loader5.addEventListener(Event.COMPLETE, function(e:Event){
basketmtdtarget.text = loader5.data
})
if(new_clp){
new_clp.parent.removeChild(new_clp)
new_clp = null
}
if(new_clp2){
new_clp2.parent.removeChild(new_clp2)
new_clp2 = null
}
if(new_clp3){
new_clp3.parent.removeChild(new_clp3)
new_clp3 = null
}
trace('new_clp : '+new_clp)
trace('new_clp2 : '+new_clp2)
trace('new_clp3 : '+new_clp3)
var clp_index = parseInt(bdaily.text) >= parseInt(basketdtarget.text) ? 1 : 2
new_clp = clp_index == 1 ? new clp_01() : new clp_02()
addChild(new_clp)
var clp_index2 = parseInt(bwtd.text) >= parseInt(basketwtdtarget.text) ? 1 : 2
new_clp2 = clp_index2 == 1 ? new clp_03() : new clp_04()
addChild(new_clp2)
var clp_index3 = parseInt(bmtd.text) >= parseInt(basketmtdtarget.text) ? 1 : 2
new_clp3 = clp_index3 == 1 ? new clp_05() : new clp_06()
addChild(new_clp3)
}
This is the simplest way, you can optimize it later.