By Jon on May 31, 2021 03:58 am i have query select case when (status = 'MENANG' is null ) then '0' when (status = 'KALAH' is null) then '0' when (status = 'PROSES' is null) then '0' when (status = 'BATAL' is null) then '0' when (status = 'MUNDUR' is null) then '0' else status end as data_status, count(a.kode_barang) as total from tbl barang group by status here I have a query and some status, here I use the count to calculate the number of items based on status when run, data_status | jumlah (count) KALAH 2 kosong 4 MENANG 2 PROSES 11 how to display status which value is 0 or null ? Read in browser »  By abhey on May 31, 2021 03:58 am I have used every solution available on the internet or stackoverflow. I want to add some external js files and get it work after I request some data from the server or route to different page. If you want me to attach the code files Let me know. Please help me solve this problem Read in browser »  By Jui on May 31, 2021 03:57 am I have installed the 'econml' package but when I try to import DML, using : from econml.dml import DML I am getting the following error: 'ImportError: cannot import name 'show_config' from 'numpy' (unknown location)' I am wondering how can I fix this issue. Read in browser »  By Gunt.r on May 31, 2021 03:57 am I am trying to take an xml document parsed with lxml objectify in python and add subelements to it. The problem is that I can't work out how to do this. The only real option I've found is a complete reconstruction of the data with objectify.Element and objectify.SubElement, but that... doesn't make any sense. With JSON for instance, I can just import the data as an object and navigate to any section and read, add and edit data super easily. How do I parse an xml document with objectify so that I can add subelement data to it? data.xml <?xml version='1.0' encoding='UTF-8'?> <data> <items> <item> text_1 </item> <item> text_2 </item> </items> </data> I'm sure there is an answer on how to do this online but my search terminology is either bad or im dumb, but I can't find a solution to this question. I'm sorry if this is a duplicate question. Read in browser »  By user13624758 on May 31, 2021 03:57 am I am doing a school project using react native that plays MP3 files on devices and modifying tempo/bpm of the song to a specific value. I have searched up all the available audio libraries and the closest I have got is react-native-track-player which allows me to adjust playrate. However, it does not allow me to get the tempo/bpm of the original song to make fine adjustments. Anyone can recommend a suitable library/alternative that I might have missed out for this problem? Preferably do-able in react-native. Read in browser »  By Nahuel Mel on May 31, 2021 03:57 am This is my code import os pwd = os.getcwd() playlist_links = ['A', 'B', 'C', 'D', 'E', 'F',] for link in playlist_links: # Create the path path = os.path.join(pwd, link) # Create the directory if not os.path.exists(path): os.mkdir(path) os.chdir(path) with open("Z:/www.rttv.com/Change_Into_Dir_TEST/single-video-v5-{}.txt".format(link), 'w', encoding="utf-8") as output_file: output_file.write(link) os.chdir(pwd) This is the output I get: What I want is to have each txt file in its respected folder. For example: single-video-v5-A.txt should be in the A folder single-video-v5-B.txt should be in the B folder single-video-v5-C.txt should be in the C folder And so on and so forth... What exactly is wrong with my code? I would greatly appreciate any help. Thank you in advance! Read in browser »  By py_tester on May 31, 2021 03:56 am I want to generate a pdf report containing data in a vertical table. Is there any library to achieve this functionality? I can use the following format of the dictionary to render data context = { "name":["A","B","C","D","E"] "age":[23,23,23,23,23], } but data is huge so it can affect performance.is there any other way to achieve this?I just want to generate pdf report with the table in the following format : | Name | A | 23 | | Age | B | 23 |
Read in browser »  By user3174558 on May 31, 2021 03:56 am i have a Webbrowser Control on my Form. I load an Images from my ApplicationStartupPath via html Table. See code here: <table width=100% height=100% border="0"> <tr> <td style="text-align: center; vertical-align: middle;"> <img src=".\load.gif" /> </td> </tr> the image load.gif is in the same directory then i load in the Webbrowse via: load2.Navigate(Application.StartupPath + "\\load.html"); on first form opening my gif is fine and animating. on the second opening the gif is no longer animating. what can i do here? reload is not working. Read in browser »  By trannguyenhan on May 31, 2021 03:56 am I run a Spark Streaming program written in Java to read data from Kafka, but am getting this error, I tried to find out it might be because my version using scala or java is low. I used JDK version 15 and still got this error, can anyone help me to solve this error? Thank you. This is terminal when i run project : Exception in thread "main" java.lang.NoClassDefFoundError: scala/Product$class at org.apache.spark.streaming.kafka010.PreferConsistent$.<init>(LocationStrategy.scala:42) at org.apache.spark.streaming.kafka010.PreferConsistent$.<clinit>(LocationStrategy.scala) at org.apache.spark.streaming.kafka010.LocationStrategies$.PreferConsistent(LocationStrategy.scala:66) at org.apache.spark.streaming.kafka010.LocationStrategies.PreferConsistent(LocationStrategy.scala) at demo.KafkaDemo.main(KafkaDemo.java:47) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:564) at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52) at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:951) at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:180) at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:203) at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:90) at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:1030) at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:1039) at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) Caused by: java.lang.ClassNotFoundException: scala.Product$class at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:435) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 17 more 21/05/31 14:42:51 INFO SparkContext: Invoking stop() from shutdown hook 21/05/31 14:42:51 INFO SparkUI: Stopped Spark web UI at http://192.168.1.24:4040 21/05/31 14:42:51 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped! 21/05/31 14:42:51 INFO MemoryStore: MemoryStore cleared 21/05/31 14:42:51 INFO BlockManager: BlockManager stopped 21/05/31 14:42:51 INFO BlockManagerMaster: BlockManagerMaster stopped 21/05/31 14:42:51 INFO OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped! 21/05/31 14:42:51 INFO SparkContext: Successfully stopped SparkContext 21/05/31 14:42:51 INFO ShutdownHookManager: Shutdown hook called 21/05/31 14:42:51 INFO ShutdownHookManager: Deleting directory /tmp/spark-9bf7b2b8-aa48-4d13-91d6-7efd096200ef 21/05/31 14:42:51 INFO ShutdownHookManager: Deleting directory /tmp/spark-0cabea66-391d-4376-b851-02b923209992 This is file pom.xml of project : <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>TikiData</groupId> <artifactId>TikiData</artifactId> <version>V1</version> <dependencies> <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.6</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-client --> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-client</artifactId> <version>3.3.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-sql --> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-sql_2.12</artifactId> <version>3.1.1</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-streaming-kafka-0-10 --> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-streaming-kafka-0-10_2.11</artifactId> <version>2.0.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.spark/spark-streaming --> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-streaming_2.11</artifactId> <version>2.3.3</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/org.scala-lang/scala-library --> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>2.12.12</version> </dependency> <!-- https://mvnrepository.com/artifact/org.scala-lang/scala-compiler --> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-compiler</artifactId> <version>2.12.12</version> </dependency> <!-- https://mvnrepository.com/artifact/org.scala-lang/scala-reflect --> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-reflect</artifactId> <version>2.12.13</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.kafka/kafka-clients --> <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId> <version>2.7.0</version> </dependency> </dependencies> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <release>15</release> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <archive> <manifest> <mainClass> demo.KafkaDemo </mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </execution> </executions> </plugin> <plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> <version>4.4.0</version> <configuration> <scalaVersion>2.12.2</scalaVersion> </configuration> </plugin> </plugins> </build> This is file main of project : package demo; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Map; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.common.serialization.StringDeserializer; import org.apache.spark.SparkConf; import org.apache.spark.api.java.function.FlatMapFunction; import org.apache.spark.api.java.function.Function; import org.apache.spark.api.java.function.Function2; import org.apache.spark.api.java.function.PairFunction; import org.apache.spark.streaming.Durations; import org.apache.spark.streaming.api.java.JavaDStream; import org.apache.spark.streaming.api.java.JavaInputDStream; import org.apache.spark.streaming.api.java.JavaPairDStream; import org.apache.spark.streaming.api.java.JavaStreamingContext; import org.apache.spark.streaming.kafka010.ConsumerStrategies; import org.apache.spark.streaming.kafka010.KafkaUtils; import org.apache.spark.streaming.kafka010.LocationStrategies; import scala.Tuple2; public class KafkaDemo { public static void main(String args) throws InterruptedException { // Create a local StreamingContext and batch interval of 10 second SparkConf conf = new SparkConf().setMaster("local").setAppName("Kafka Spark Integration"); JavaStreamingContext jssc = new JavaStreamingContext(conf, Durations.seconds(10)); //Define Kafka parameter Map<String, Object> kafkaParams = new HashMap<String, Object>(); kafkaParams.put("bootstrap.servers", "localhost:9092"); kafkaParams.put("key.deserializer", StringDeserializer.class); kafkaParams.put("value.deserializer", StringDeserializer.class); kafkaParams.put("group.id", "0"); // Automatically reset the offset to the earliest offset kafkaParams.put("auto.offset.reset", "earliest"); kafkaParams.put("enable.auto.commit", false); //Define a list of Kafka topic to subscribe Collection<String> topics = Arrays.asList("hello-kafka"); //Create an input Dstream which consume message from Kafka topics JavaInputDStream<ConsumerRecord<String, String>> stream; stream = KafkaUtils.createDirectStream(jssc,LocationStrategies.PreferConsistent(),ConsumerStrategies.Subscribe(topics, kafkaParams)); // Read value of each message from Kafka JavaDStream<String> lines = stream.map((Function<ConsumerRecord<String, String>, String>) kafkaRecord -> kafkaRecord.value()); // Split message into words JavaDStream<String> words = lines.flatMap((FlatMapFunction<String, String>) line -> Arrays.asList(line.split(" ")).iterator()); // Take every word and return Tuple with (word,1) JavaPairDStream<String,Integer> wordMap = words.mapToPair((PairFunction<String, String, Integer>) word -> new Tuple2<>(word,1)); // Count occurance of each word JavaPairDStream<String,Integer> wordCount = wordMap.reduceByKey((Function2<Integer, Integer, Integer>) (first, second) -> first+second); //Print the word count wordCount.print(); // Start the computation jssc.start(); jssc.awaitTermination(); } }
Read in browser »  By Leonardo on May 31, 2021 03:56 am When creating a Smart Folder on Mac OS and choose "Kind is Movie" the corresponding search Key in the .savedsearch file created by macOS seems to be kMDItemKind. Just because files have different kMDItemKind values and sometimes they don't seem to have a value at all, I wonder how Spotlight knows that a file is a "Movie". For example by running the following mdls: mdls ~/MyFolder/MyMovie.avi |grep kMDItemKind no results mdls ~/MyFolder/MyMovie.mp4 |grep kMDItemKind kMDItemKind = "Filmato MPEG-4" mdls ~/MyFolder/MyMovie.wmw |grep kMDItemKind kMDItemKind = "Matroska Video File" However, the .avi file and .mp4 file both appear in SmartFolder while the .mkv doesn't, even tough it is supposed to be a movie. So, Is there maybe a dictionary or a function that can eventually be altered or expanded with further options ? Read in browser »  By Angelin on May 31, 2021 03:51 am I am using React Bootstrap, I am using map function of javascript to loop through admins, when i loop through them all values outside the modal display the correct values from the admins array, but inside the modal it shows only one standard object from the array everytime. The id of that component is different outside the modal and inside the modal, the modal inside displays only the user with id 1 in every component or every time the modal is clicked admins = [ {id: 5, email: "angelinsneha@gmail.com", name: "angelin", role: "admin"}, {id: 4, email: "angelinsneha14@gmail.com", name: "angu", role: "admin"}, {id: 1, email: "angelin@gmail.com", name: "aanjuu", role: "admin"}] <div className="rgtss pb-5"> {admins.length > 0 ? admins.map((i) => ( <div className="bdr"> <div> <p>{i.name} {i.id}</p> <span>{i.email}</span> </div> <div className="mt-3"> <p>{i.role}</p> </div> <div> <DropdownButton id="dropdown-basic-button" variant="dark" title="" size="sm" > <Dropdown.Item href={id == i.id ? "/profile" : ""}> Edit </Dropdown.Item> {4 == i.id ? ( "" ) : ( <Dropdown.Item onClick={handleShow}>Delete {i.id}</Dropdown.Item> )} </DropdownButton> <Modal show={show} onHide={handleClose}> <Modal.Header closeButton> <Modal.Title>Delete Account {i.id}</Modal.Title> // only id 1 is displayed in modal, everytime the loop runs </Modal.Header> <Modal.Body> Are you sure you want to delete this team account:{" "} <b>{i.name}</b>? </Modal.Body> <Modal.Footer> <Button variant="secondary" onClick={handleClose}> Close </Button> <Button variant="danger" onClick={() => handledelete(i.id)} > Delete </Button> </Modal.Footer> </Modal> </div> </div> )) : ""} </div> I have no idea why this is happening, can you'll help me? Read in browser »  By Developer Mahavir on May 31, 2021 03:51 am I am trying to implement https://pub.dev/packages/gps. But while using it it is throwing following exception- MissingPluginException(No implementation found for method gps on channel top.kikt/gps) what is this exception and how to fix it. note -I can not use other libraries it is necessary to implement this library. i wrote this code to access current position but this piece of code returning null to me var position = await Gps.currentGps(); build.gradle info compileSdkVersion 28 minSdkVersion 16 targetSdkVersion 28 var position = await Gps.currentGps(); manifest permission I added- <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> Read in browser »  By Sami Kärnä on May 31, 2021 03:50 am So as you can see the "add" button works fine but I can´t make the clear button to work for some reason. I am losing my sh*t any minute now. Please help. function addToList() { let x = document.getElementById("add").value let y = document.createElement("li") y.textContent = x document.getElementById("list").appendChild(y) } function clear() { ???? } <body> <div class="thebox"> <h1>TO DO LIST</h1> <input type="text" id="add"> <button id="btn1" onclick="addToList()">add </button> <button id="btn2" onclick="clear()">clear</button> <ul id="list"></ul> </div> Read in browser »  By John Honai on May 31, 2021 03:50 am TXT_0 = "◻️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️" TXT_1 = "⬛️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️" TXT_2 = "⬛️ ⬛️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️" TXT_3 = "⬛️ ⬛️ ⬛️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️" TXT_4 = "⬛️ ⬛️ ⬛️ ⬛️ ◻️ ◻️ ◻️ ◻️ ◻️ ◻️" TXT_5 = "⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ◻️ ◻️ ◻️ ◻️ ◻️" TXT_6 = "⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ◻️ ◻️ ◻️ ◻️" TXT_7 = "⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ◻️ ◻️ ◻️" TXT_8 = "⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ◻️ ◻️" TXT_9 = "⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ◻️" TXT_10 = "⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️ ⬛️" 'x' is a real-time integer variable from a percentage calculation function. Eg: if x < 10: print(TXT_0) if (x >= 10) and (x < 20): print(TXT_1) I want to print the above text like a percentage display! Need to print the corresponding string with respect to the input between 0 - 100! Read in browser »  By shammeee on May 31, 2021 03:46 am I have two tables the first table have regular price and discounted price. I'm trying to count how many regular price and discounted price and put the values in second table. Read in browser »  By Ana on May 31, 2021 03:46 am [Hello hope you are well! I want to create a row with gridsytems in bootstrap which contain seven images horizontal for desktop and display for one column in mobile for all types of devices to be responsive. If anyone have any answer please reply me.][2]*** Read in browser »  By Aryaan Bhimani on May 31, 2021 03:42 am I am not exactly sure how to describe it but I want to create this curved design with CSS: The current bad solution is creating a semi-oval in white that cuts into the bottom color but creating a semi-oval is not very smooth. Here is what I have: My code for the semi-oval: <div style={{ backgroundColor: 'white', height: '100px', width: '100%', borderRadius: '50%/100%', borderTopLeftRadius: '0', borderTopRightRadius: '0', position: 'absolute', left: '50%', transform: 'translate(-50%, 0%)' }}> </div> The top picture looks a lot smoother which is what I am trying to go for. Read in browser »  By Nguyễn Hoàng Sơn on May 31, 2021 03:42 am like my title said I struggle with this though below is a example { id: '1', name: 'one' }, { id: '2', name: 'two' }, { id: '3', name: 'three' }, { id: '4', name: 'four' }, this is a flatlist after I remove item with id '2' I want id 3 become 2 and id 4 become 3 so the flatlist after id 2 be removed will like { id: '1', name: 'one' }, { id: '2', name: 'three' }, { id: '3', name: 'four' }, here is my code export default function Listdata({ route }) { const [itemData, newItem] = React.useState(); const [itemState, setItemState] = React.useState(itemData); const [idmoi, incr,] = React.useState(1); const [textNhapVao, setTextNhapVao] = React.useState(''); const tinhToanId = (t) => { var idNew = [itemData.id]; incr(idNew - 1); } const themItem = () => { var arrayMoi = [...itemData, { id: idmoi, name: textNhapVao }]; incr(idmoi + 1) console.log('idddd') console.log(idmoi) setItemState(arrayMoi); newItem(arrayMoi); } <View> </View> const keyboardVerticalOffset = Platform.OS === 'ios' ? 40 : 0 const xoaItem = (IItem) => { console.log('routeeee') console.log(route.params.paramKey) setItemState(prevItemState => prevItemState.filter((_item, _Index) => _Index !== IItem)); } return ( <Container style={styles.container}> <View style={{ alignItems: 'center', justifyContent: 'center', borderBottomWidth: 1, borderColor: '#d7d7d7', }}> <Text style={{ fontWeight: 'bold', fontSize: 30, color: 'green' }}>Xin Chào {route.params.paramKey}</Text> </View> <FlatList data={itemState} keyExtractor={(item, index) => index} renderItem={({ item, index }) => ( <View style={{ flexDirection: 'row', justifyContent: 'space-between' }}> <View style={{ marginLeft: 20 }}> <Text style={{ fontSize: 30, color: 'red' }} >{item.id}{'\n'}{item.name}</Text> </View> <View style={{ justifyContent: 'center', marginRight: 20 }}> <TouchableOpacity style={{ width: '100%', backgroundColor: 'red', }} activeOpacity={0.7} onPress={() => xoaItem(index)} > <IconFE name='trash-2' size={30} style={{ color: 'orange' }} /> </TouchableOpacity> </View> </View> )} /> <View style={{ position: 'relative', height: 50, borderTopWidth: 1, borderColor: '#d7d7d7', }}> <KeyboardAvoidingView enabled behavior={Platform.OS === "ios" ? "padding" : null} keyboardVerticalOffset={keyboardVerticalOffset} > <View style={{ alignItems: 'center', position: 'relative', flexDirection: 'row', justifyContent: 'space-between', marginLeft: 20, marginRight: 20, }}> <Input onChangeText={data => setTextNhapVao(data)} placeholder='Nhập Vào Đây'></Input> <TouchableOpacity title="Thêm" onPress={themItem}> <IconFE name='check-square' size={30} style={{ color: 'blue' }} /> </TouchableOpacity> </View> </KeyboardAvoidingView> </View> </Container> ) } and below is my screenshot flatlist plzz help thank you https://uphinh.org/image/9OLoCN Read in browser »  By Jayesh Dhandha on May 31, 2021 03:34 am Below is my sample class. public class TuningConfig { private List<String> features; private List<Integer> numberOfTerms; private List<String> importance; public List<String> getFeatures() { return features; } public void setFeatures(List<String> features) { this.features = features; } public List<Integer> getNumberOfTerms() { return numberOfTerms; } public void setNumberOfTerms(List<Integer> numberOfTerms) { this.numberOfTerms = numberOfTerms; } public List<String> getImportance() { return importance; } public void setImportance(List<String> importance) { this.importance = importance; } } It contains 3 lists (There might be more or less) and in request i might get any of this list (some may empty) If my all lists has some possible values then i can easily create combinations using nested loops & recursion. But how can i create combinations efficiently if let say 1 or 2 lists are empty so i ignore them and create combinations of other non empty lists. Sample request: features: ['A', 'B'] numberOfTerms: [15, 25] Expected Output: TuningConfig(s) : { feature: 'A', numberOfTerms: 15 }, { feature: 'A', numberOfTerms: 25 }, { feature: 'B', numberOfTerms: 15 }, { feature: 'B', numberOfTerms: 25 } I might need another class which will store this using combinations (as they are not multivalued) Any standard Java library for that? Any help will be highly appreciated. Read in browser »  By Tom Lau on May 31, 2021 03:25 am I have a table named T: | Industry | stock | trdType | nr | qty | | TMT | Tencent | active | 30 | 1 | | TMT | Tencent | normal | 20 | 2 | | TMT | Tencent | passive | 50 | 3 | | TMT | Alibaba | active | 20 | 4 | | TMT | Alibaba | normal | 50 | 5 | | TMT | Alibaba | passive | 30 | 6 | is there any SQL trick to generate a result like (column names are automatically generated by enum?): | Industry | stock | active_nr | active_nr% | normal_nr | normal_nr% | passive_nr | passive_nr% | | TMT | Tencent | 30 | 30% | 20 | 20% | 50 | 50% | | TMT | Alibaba | 20 | 20% | 50 | 50% | 30 | 30% | Thank you, Edited: the math behind %: - first group by stock, for example "Tencent"
- then sum(active, normal, passive) should be a total (say 100 here), so the percentage of Tencent active_nr should be 30/(30+20+50) = 30%.
- Same logic for Tencent normal_nr and passive_nr
- Same logic for Alibaba-wise
Read in browser »  By Sagun Raj Lage on May 31, 2021 02:34 am I have two classes, BedRequest and RequestThing: class BedRequest extends Model { use HasFactory; protected $table = 'bed_request'; protected $guarded = ; public function requests() { return $this->belongsTo(RequestThing::class, 'request_id'); } } class RequestThing extends Model { use HasFactory; protected $table = 'requests'; protected $guarded = ; public function bedRequests() { return $this->belongsTo(BedRequest::class); } } I am trying to get the following output format, where post_status and created_at are the fields of BedRequest and requests key holds the data fetched in relationship with RequestThing: [ { "post_status": 0, "created_at": "2021-05-03T08:29:37.000000Z", "requests": { "id": 128, "name": "John Doe", "age": "52", "gender": "male", "contact": "9101235456", "address": "Kentucky", "urgency": "urgent", "reason": "Some reason", "filler_name": "Mahim", "filler_contact": "9160236160", "filler_address": "Bali", "filler_relation": "others", "created_at": "2021-05-03T08:29:37.000000Z", "updated_at": "2021-05-03T09:47:17.000000Z" } } ] So, I wrote the following code in my controller: public function bedRequest() { $bedRequests = BedRequest::where(['approved' => 1, 'post_status' => 0])->with('requests')->get(['post_status', 'created_at']); return $bedRequests; } But when I did that, the response I got was: [ { "post_status": 0, "created_at": "2021-05-03T08:29:37.000000Z", "requests": null } ] The requests key gives null value. However, if I do the following (i.e. remove the parameters from get(), the requests key gets populated with data and I receive the whole data of BedRequest as well. But, I just need post_status and created_at from BedRequest and requests that holds the data from RequestThing. Could anyone please suggest a solution? Read in browser »  By Md. Samin Abrar on May 31, 2021 02:23 am I am want to replace a specific part of the string while using textwrap. But I am getting an unwanted line break. I have tried a lot of ways but still it is not working. here is my code. import textwrap import math def wrap(string, max_width): wrapper = textwrap.TextWrapper(width = max_width) word_list = wrapper.fill(text = string) return word_list height, width = map(int,input().split()) square = height * width i = 0 x = while i < square: x.append("-") i += 1 k = 0 while k < math.floor(height / 2): line = math.floor(width / 2) + width * k x[line] = '|' x[line + 1]= "." x[line - 1] = "." for h in range(1, k + 1): f = h * 3 line_plus = line + f line_minus = line - f x[line_plus] = '|' x[line_minus] = '|' x[line_minus - 1] = '.' x[line_plus - 1] = '.' x[line_minus + 1] = '.' q = line_plus + 1 x[q] = '.' k += 1 a = 0 while a < math.floor(height / 2): line = math.floor(width / 2) + width * a line_end = (math.floor(width / 2) + width * a) * (-1) x[line_end - 1] = '|' if line > width: x[line_end + 2] = '|' x[line_end - 4] = '|' a += 1 listToStr = ''.join([str(elem) for elem in x]) welcome_pos = math.floor(height / 2) * width + (math.floor(width / 2) - math.floor(7 / 2)) s = listToStr[ 0: welcome_pos] + "welcome" + listToStr[welcome_pos + 7:] print(wrap(listToStr, width) + "\n") print(wrap(s, width)) I want to stay the string the same way listToStr while adding 'welcome'. Read in browser »  By Ben on May 31, 2021 02:21 am I need a stored procedure where I do two things. First I want to get all schema names that is prefixed with 'myschema_', so I've done this: SELECT schema_name FROM information_schema.schemata WHERE schema_name LIKE 'myschema_%' Next, I want a while loop that loops through each schema and gets 'name' from the 'person' table. This means that I somehow have to feed the result from the first select schema statement in as a parameter in the next call. And all of this should be one stored procedure. How do I do this? Read in browser »  By benschbob91 on May 31, 2021 02:21 am My question is based on this question: Adjust hspace for some of the subplots Which adjusts the top plot of a number of subplots and increases the difference in hspace. I want to increase the hspace between two plots within the subplots (in my case: between plot 3 and plot4 from the top). Here is my example: import numpy as np import matplotlib.pyplot as plt noise = np.random.rand(300) gs_top = plt.GridSpec(9, 1, hspace=0.5) gs_base = plt.GridSpec(9, 1, hspace=0) fig = plt.figure() fig.patch.set_facecolor('white') ax0 = fig.add_subplot(gs_base[0,:]) ax1 = fig.add_subplot(gs_base[1,:]) ax2 = fig.add_subplot(gs_top[2,:]) ax3 = fig.add_subplot(gs_base[3,:]) ax4 = fig.add_subplot(gs_base[4,:]) ax5 = fig.add_subplot(gs_base[5,:]) ax0.plot(noise) ax1.plot(noise) ax2.plot(noise) ax3.plot(noise) ax4.plot(noise) ax5.plot(noise) In the example it is shown that the hspace increases between plot 3 and 4. However, I don't want to increase the space between plot 2 and plot 3. How can I adjust the hspace variable only on one side? Read in browser »  By Farzam on May 31, 2021 01:59 am I have the following html code: <div class='c'>Title1</div> <div class='c'>blue</div> <div class='c'>Title2</div> <div class='c'>red</div> <div class='c'>Title3</div> <div class='c'>green</div> <div class='c'>Title4</div> <div class='c'>blue</div> <div class='c'>Title5</div> <div class='c'>red</div> <div class='c'>Title6</div> <div class='c'>green</div> I need to get 'title' when the color is 'red' ,in this case I need = ['Title2' , 'Title5'] as a python list How I can do that with using Python3 Beautifulsoup4 library? Read in browser »  By Tburg on May 31, 2021 12:52 am SQL....On my table I have attribute table with "Pat0700-1700" on my report I want to drop the Pat and only display 0700-1700. How would I accomplish this on SQL. I have search and tried the substring with neg results. Read in browser »  By Robert Hovhannisyan on May 30, 2021 10:36 am I'm learning linear algebra and trying to make a little program with basic linear transformations (rotating, scaling, translating). Here is the full working example: https://codesandbox.io/embed/determined-diffie-t2iy5?fontsize=14&hidenavigation=1&theme=dark I wrote functions for generating each matrix for each transformation and functions to calculate them (multiplying matrix with a point, multiplying matrices). export const multiplyMatrixWithPoint = (matrix, point) => { return point.map((dimension, index) => { let result = 0; for (let i = 0; i < 4; i++) { const matrixIndex = index * 4 + i; result += dimension * matrix[matrixIndex]; } return +result.toFixed(2); }) }; // Just creating 2D array to make it easy to calculate the matrix export const matrixToPoints = matrix => { const result = ; for (let i = 0; i < 4; i++) { const onePoint = ; for (let j = 0; j < 4; j++) { onePoint.push(matrix[4 * i + j]); } result.push(onePoint); } return result; }; // Just making 2D array to 1D export const pointsToMatrix = points => points.reduce((acc, points) => [...acc, ...points], ); // Transpose function to make the matrix multiplication correct export const transposeCSSMatrixToTransform = matrix => matrix[0].map((column, index) => matrix.map(row => row[index])); export const multiplyMatrices = (matrixA, matrixB) => { const separatePoints = transposeCSSMatrixToTransform(matrixToPoints(matrixB)); return pointsToMatrix(transposeCSSMatrixToTransform(separatePoints.map(point => multiplyMatrixWithPoint(matrixA, point)))); }; export const rotationMatrixGenerator = (matrix, angle) => { const radians = degreeToRadian(angle); matrix[0] = Math.cos(radians); matrix[1] = -Math.sin(radians); matrix[4] = Math.sin(radians); matrix[5] = Math.cos(radians); return matrix; }; export const scaleMatrixGenerator = (matrix, { x, y }) => { matrix[0] = x; matrix[5] = y; return matrix; }; export const translateMatrixGenerator = (matrix, { x, y }) => { matrix[12] = x; matrix[13] = y; return matrix; }; For showing the transformations I used CSS's matrix3d export const matrixToCSSMatrix = matrix => `matrix3d(${matrix.join(',')})`; And here are the executing part of the code ... const [matrix, setMatrix] = useState(DEFAULT_MATRIX); const [rotationAngle, setRotationAngle] = useState(0); const [scale, setScale] = useState(DEFAULT_XY); const [translate, setTranslate] = useState(DEFAULT_XY); const classes = useStyles(); const { app } = classes; // ---------------------- Rotate --------------------- // const rotate = useCallback(e => { const { value: angle } = e.target; const rotationMatrix = rotationMatrixGenerator(matrix, +angle); const updatedMatrix = multiplyMatrices(matrix, rotationMatrix); setMatrix(updatedMatrix); setRotationAngle(angle); }, [matrix]); // ---------------------- Scale --------------------- // const changeScale = useCallback((e, dimension) => { const { value } = e.target; const updatedScale = { ...scale, [dimension]: +value }; const scaleMatrix = scaleMatrixGenerator(matrix, updatedScale); const updatedMatrix = multiplyMatrices(matrix, scaleMatrix); setMatrix(scaleMatrix); setScale(updatedScale); }, [matrix, scale]); // ------------------ Translate --------------------- // const changeTranslation = useCallback((e, position) => { const { value } = e.target; const updatedTranslation = { ...translate, [position]: +value }; const translateMatrix = translateMatrixGenerator(matrix, updatedTranslation); const updatedMatrix = multiplyMatrices(matrix, translateMatrix); setMatrix(translateMatrix); setTranslate(updatedTranslation); }, [matrix, translate]); ... Firstly I thought it's because I didn't transpose the matrix, I tried to transpose it, it helped a little but didn't fix all bugs. Also, I tried to collect all transformations and apply them at once, but it was a very bad solution and didn't work well. I need to have a separate rotation, scaling and transition, but rotation and transition are didn't work well because they are using the same segments of matrix. Also, I can't achieve normal rotation against Z-axis. Read in browser »  Recent Articles:
|
No comments:
Post a Comment